Lines Matching defs:log

11 #include "fts-expunge-log.h"
28 /* Total number of messages expunged so far in this log */
46 struct fts_expunge_log *log;
56 struct fts_expunge_log *log;
69 struct fts_expunge_log *log;
71 log = i_new(struct fts_expunge_log, 1);
72 log->path = i_strdup(path);
73 log->fd = -1;
74 return log;
79 struct fts_expunge_log *log = *_log;
82 i_close_fd(&log->fd);
83 i_free(log->path);
84 i_free(log);
87 static int fts_expunge_log_open(struct fts_expunge_log *log, bool create)
91 i_assert(log->fd == -1);
94 fd = open(log->path, O_RDWR | O_APPEND | (create ? O_CREAT : 0), 0600);
99 i_error("open(%s) failed: %m", log->path);
102 if (fstat(fd, &log->st) < 0) {
103 i_error("fstat(%s) failed: %m", log->path);
107 log->fd = fd;
112 fts_expunge_log_reopen_if_needed(struct fts_expunge_log *log, bool create)
116 if (log->fd == -1)
117 return fts_expunge_log_open(log, create);
119 if (stat(log->path, &st) == 0) {
120 if (st.st_ino == log->st.st_ino &&
121 CMP_DEV_T(st.st_dev, log->st.st_dev)) {
129 i_error("stat(%s) failed: %m", log->path);
132 if (close(log->fd) < 0)
133 i_error("close(%s) failed: %m", log->path);
134 log->fd = -1;
135 return fts_expunge_log_open(log, create);
139 fts_expunge_log_read_expunge_count(struct fts_expunge_log *log,
144 i_assert(log->fd != -1);
146 if (fstat(log->fd, &log->st) < 0) {
147 i_error("fstat(%s) failed: %m", log->path);
150 if ((uoff_t)log->st.st_size < sizeof(*expunge_count_r)) {
158 ret = pread(log->fd, expunge_count_r, sizeof(*expunge_count_r),
159 log->st.st_size - 4);
161 i_error("pread(%s) failed: %m", log->path);
165 i_error("pread(%s) read only %d of %d bytes", log->path,
173 fts_expunge_log_append_begin(struct fts_expunge_log *log)
178 pool = pool_alloconly_create("fts expunge log append", 1024);
180 ctx->log = log;
184 if (log != NULL && fts_expunge_log_reopen_if_needed(log, TRUE) < 0)
242 /* To be honest, an unbacked log doesn't need to maintain the uids_count,
243 but we don't know here if we're supporting an unbacked log or not, so we
302 struct fts_expunge_log *log = ctx->log;
308 i_assert(log != NULL);
311 if (fts_expunge_log_reopen_if_needed(log, TRUE) < 0)
314 if (fts_expunge_log_read_expunge_count(log, &expunge_count) < 0)
322 if ((ret = write_full(log->fd, buf->data, buf->used)) < 0) {
323 i_error("write(%s) failed: %m", log->path);
324 if (ftruncate(log->fd, log->st.st_size) < 0)
325 i_error("ftruncate(%s) failed: %m", log->path);
327 if ((ret = fts_expunge_log_reopen_if_needed(log, TRUE)) <= 0)
329 /* the log was unlinked, so we'll need to write again to
341 /* finish by closing the log. this forces NFS to flush the
344 if (close(log->fd) < 0) {
347 i_error("close(%s) failed: %m", log->path);
350 log->fd = -1;
370 int fts_expunge_log_uid_count(struct fts_expunge_log *log,
375 if ((ret = fts_expunge_log_reopen_if_needed(log, FALSE)) <= 0) {
380 return fts_expunge_log_read_expunge_count(log, expunges_r);
394 fts_expunge_log_read_begin(struct fts_expunge_log *log)
399 ctx->log = log;
400 if (fts_expunge_log_reopen_if_needed(log, FALSE) < 0)
402 else if (log->fd != -1)
403 ctx->input = i_stream_create_fd(log->fd, (size_t)-1);
426 i_error("read(%s) failed: %s", ctx->log->path,
431 i_error("Corrupted fts expunge log %s: "
433 ctx->log->path, size, wanted_size);
454 i_unlink_if_exists(ctx->log->path);
473 i_error("Corrupted fts expunge log %s: "
475 ctx->log->path, rec->record_size);
493 i_error("Corrupted fts expunge log %s: "
495 ctx->log->path, checksum, rec->checksum);
520 i_unlink_if_exists(ctx->log->path);
589 i_warning("fts: Expunge log subtract ignored %u nonexistent mailbox GUIDs",
593 /* It could be argued that somehow adding a log (file) to the append context