[dovecot-cvs] dovecot/src/lib-storage/index/dbox dbox-uidlist.c, 1.35, 1.36

cras at dovecot.org cras at dovecot.org
Sun Jul 23 22:01:07 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index/dbox
In directory talvi:/tmp/cvs-serv1860

Modified Files:
	dbox-uidlist.c 
Log Message:
When saving new mails, append the changes to uidlist file, but only when
doing so doesn't temporarily move the file's mtime backwards.



Index: dbox-uidlist.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-uidlist.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- dbox-uidlist.c	23 Jul 2006 15:37:56 -0000	1.35
+++ dbox-uidlist.c	23 Jul 2006 19:01:03 -0000	1.36
@@ -22,6 +22,7 @@
 #include <utime.h>
 #include <sys/stat.h>
 
+#define DBOX_SYNC_SECS 1
 #define DBOX_APPEND_MAX_OPEN_FDS 64
 
 #define DBOX_UIDLIST_VERSION 1
@@ -735,11 +736,22 @@
 	unsigned int i, count;
 	uint32_t uid_start;
 	string_t *str;
-	int ret = 0;
+	int ret = 1;
 
 	i_assert(ctx->uidlist->fd != -1);
 	i_assert(ctx->uidlist->lock_fd != -1);
 
+	if (fstat(ctx->uidlist->fd, &st) < 0) {
+		mail_storage_set_critical(STORAGE(ctx->uidlist->mbox->storage),
+			"fstat(%s) failed: %m", ctx->uidlist->path);
+		return -1;
+	}
+	if (st.st_mtime >= ioloop_time-DBOX_SYNC_SECS) {
+		/* we can't update this file without temporarily moving mtime
+		   backwards */
+		return 0;
+	}
+
 	if (lseek(ctx->uidlist->fd, 0, SEEK_END) < 0) {
 		mail_storage_set_critical(STORAGE(ctx->uidlist->mbox->storage),
 			"lseek(%s) failed: %m", ctx->uidlist->path);
@@ -790,7 +802,7 @@
 
 	ctx->uidlist->ino = st.st_ino;
 	ctx->uidlist->mtime = ut.modtime;
-	return 0;
+	return 1;
 }
 
 static int
@@ -837,14 +849,19 @@
 	if (dbox_uidlist_write_append_offsets(ctx) < 0)
 		ret = -1;
 	else {
-		ctx->uidlist->need_full_rewrite = TRUE; // FIXME
+		if (!ctx->uidlist->need_full_rewrite) {
+			ret = dbox_uidlist_append_changes(ctx);
+			if (ret < 0)
+				return -1;
+			if (ret == 0)
+				ctx->uidlist->need_full_rewrite = TRUE;
+		}
+
 		if (ctx->uidlist->need_full_rewrite) {
 			dbox_uidlist_update_changes(ctx);
 			ret = dbox_uidlist_full_rewrite(ctx->uidlist);
 			if (ctx->uidlist->dotlock == NULL)
 				ctx->locked = FALSE;
-		} else {
-			ret = dbox_uidlist_append_changes(ctx);
 		}
 	}
 



More information about the dovecot-cvs mailing list