Patch for 2.3.9 mod time bug

Michael Glad glad at daimi.au.dk
Sun Sep 2 15:51:09 EDT 2007


I also observe the 2.3.8/9 problem with sync_server not properly
setting the mtime of sync'ed messages. 

The problem seems to be that the sync_message_fsync routine
writes (flushes) to the message file after the utime call.

I've made the enclosed patches which solve the problems at least
for me. It records the proper utime in an extra field of the
sync_message structure which is fed to a utimes call after
the flushing has been done.

	-- Michael Glad, CS Dept, Aarhus University, Denmark


--- ./imap/sync_server.c.orig-glad	2007-08-22 21:26:14.000000000 +0200
+++ ./imap/sync_server.c	2007-08-22 21:48:17.000000000 +0200
@@ -1476,6 +1476,7 @@
         message->content_lines = record.content_lines;
         message->cache_version = record.cache_version;
         message->cache_size   = mailbox_cache_size(&m, msgno);
+	message->utime = 0; /* glad */
         
         sync_message_list_cache(message_list,
                                 (char *)(m.cache_base+record.cache_offset),
@@ -1906,7 +1907,10 @@
 
             /* Set mtime of message file to be internal date */
             settime.actime = settime.modtime = item->internaldate;
+/* 
             utime(message->msg_path, &settime);
+*/
+	    message->utime = item->internaldate; /* glad */
 
             c = prot_getc(sync_in);
             break;
@@ -1945,7 +1949,11 @@
 
             /* Set mtime of message file to be internal date */
             settime.actime = settime.modtime = item->internaldate;
+/*
             utime(message->msg_path, &settime);
+*/
+	    message->utime = item->internaldate; /* glad */
+
             c = prot_getc(sync_in);
 
             break;
--- ./imap/sync_support.c.orig-glad	2007-08-22 21:25:53.000000000 +0200
+++ ./imap/sync_support.c	2007-08-22 21:26:27.000000000 +0200
@@ -962,6 +962,7 @@
 void sync_message_fsync(struct sync_message_list *l)
 {
     int i;
+    struct sync_message *current, *next; /* glad */
 
     if (l->file_count == 0)
         return;
@@ -974,6 +975,17 @@
         l->file[i] = NULL;
     }
     l->file_count = 0;
+
+    /* glad */
+    for (current = l->head; current ; current = next) {
+        next = current->next;
+        if (current->msg_path && current->utime) {
+		struct timeval utv[2];
+		utv[0].tv_sec = current->utime; utv[0].tv_usec = 0;
+		utv[1].tv_sec = current->utime; utv[1].tv_usec = 0;
+		utimes(current->msg_path, utv);
+        }
+    }
 }
 
 FILE *sync_message_open(struct sync_message_list *l,
--- ./imap/sync_support.h.orig-glad	2007-08-22 21:25:49.000000000 +0200
+++ ./imap/sync_support.h	2007-08-22 21:26:27.000000000 +0200
@@ -266,6 +266,7 @@
     char           *msg_path; /* buffer of current stage parts */
     char           *msg_path_end; /* end of buffer */
     unsigned long   msg_size;
+    unsigned long   utime; /* glad */
 };
 
 struct sync_message_list {

----- End forwarded message -----


More information about the Cyrus-devel mailing list