[dovecot-cvs] dovecot/src/lib-storage/index/dbox dbox-uidlist.c, 1.28.2.7, 1.28.2.8

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


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

Modified Files:
      Tag: branch_1_0
	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.28.2.7
retrieving revision 1.28.2.8
diff -u -d -r1.28.2.7 -r1.28.2.8
--- dbox-uidlist.c	23 Jul 2006 15:37:55 -0000	1.28.2.7
+++ dbox-uidlist.c	23 Jul 2006 19:01:02 -0000	1.28.2.8
@@ -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
@@ -736,11 +737,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);
@@ -791,7 +803,7 @@
 
 	ctx->uidlist->ino = st.st_ino;
 	ctx->uidlist->mtime = ut.modtime;
-	return 0;
+	return 1;
 }
 
 static int
@@ -838,14 +850,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