[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-file.c, 1.12, 1.13 mbox-list.c, 1.30, 1.31

cras at dovecot.org cras at dovecot.org
Sat Jan 7 02:29:22 EET 2006


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

Modified Files:
	mbox-file.c mbox-list.c 
Log Message:
Keep atime < mtime if mbox has recent messages and we're keeping them. Rely
on this for setting \UnMarked flag for LIST replies.



Index: mbox-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-file.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- mbox-file.c	8 May 2005 14:12:58 -0000	1.12
+++ mbox-file.c	7 Jan 2006 00:29:19 -0000	1.13
@@ -8,6 +8,7 @@
 #include "istream-raw-mbox.h"
 
 #include <sys/stat.h>
+#include <utime.h>
 
 int mbox_file_open(struct mbox_mailbox *mbox)
 {
@@ -96,8 +97,35 @@
 	return 0;
 }
 
+static void mbox_file_fix_atime(struct mbox_mailbox *mbox)
+{
+	struct utimbuf buf;
+	struct stat st;
+
+	if (mbox->ibox.recent_flags_count > 0 && mbox->ibox.keep_recent &&
+	    mbox->mbox_fd != -1) {
+		/* we've seen recent messages which we want to keep recent.
+		   keep file's atime lower than mtime so \Marked status
+		   gets shown while listing */
+		if (fstat(mbox->mbox_fd, &st) < 0) {
+			mbox_set_syscall_error(mbox, "fstat()");
+			return;
+		}
+		if (st.st_atime >= st.st_mtime) {
+			buf.modtime = st.st_mtime;
+			buf.actime = buf.modtime - 1;
+			if (utime(mbox->path, &buf) < 0) {
+				mbox_set_syscall_error(mbox, "utimes()");
+				return;
+			}
+		}
+	}
+}
 void mbox_file_close_stream(struct mbox_mailbox *mbox)
 {
+	/* if we read anything, fix the atime if needed */
+	mbox_file_fix_atime(mbox);
+
 	if (mbox->mbox_stream != NULL) {
 		i_stream_unref(mbox->mbox_stream);
 		mbox->mbox_stream = NULL;

Index: mbox-list.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-list.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- mbox-list.c	21 Jul 2005 19:16:31 -0000	1.30
+++ mbox-list.c	7 Jan 2006 00:29:19 -0000	1.31
@@ -10,13 +10,9 @@
 #include <dirent.h>
 #include <sys/stat.h>
 
-/* atime < mtime is a reliable way to know that something changed in the file.
-   atime >= mtime is not however reliable, especially because atime gets
-   updated whenever we open the mbox file, and STATUS/EXAMINE shouldn't change
-   \Marked mailbox to \Unmarked.. */
 #define STAT_GET_MARKED(st) \
 	((st).st_size == 0 ? MAILBOX_UNMARKED : \
-	 (st).st_atime < (st).st_mtime ? MAILBOX_MARKED : 0)
+	 (st).st_atime < (st).st_mtime ? MAILBOX_MARKED : MAILBOX_UNMARKED)
 
 struct list_dir_context {
 	struct list_dir_context *prev;



More information about the dovecot-cvs mailing list