[dovecot-cvs] dovecot/src/lib-index/mbox mbox-sync.c,1.21,1.22

cras at procontrol.fi cras at procontrol.fi
Tue Nov 12 05:58:05 EET 2002


Update of /home/cvs/dovecot/src/lib-index/mbox
In directory danu:/tmp/cvs-serv9224

Modified Files:
	mbox-sync.c 
Log Message:
If mbox file is deleted for selected folder, recreate it again so we can
handle locking issues properly. For example mutt deletes the mbox when all
mails are expunged.



Index: mbox-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-sync.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- mbox-sync.c	4 Nov 2002 09:19:19 -0000	1.21
+++ mbox-sync.c	12 Nov 2002 03:58:02 -0000	1.22
@@ -71,6 +71,7 @@
 	struct stat st;
 	time_t index_mtime;
 	uoff_t filesize;
+	int count, fd;
 
 	i_assert(index->lock_type != MAIL_LOCK_SHARED);
 
@@ -86,8 +87,20 @@
 		index_mtime = st.st_mtime;
 	}
 
-	if (stat(index->mbox_path, &st) < 0)
-		return mbox_set_syscall_error(index, "stat()");
+	count = 0;
+	while (stat(index->mbox_path, &st) < 0) {
+		if (errno != ENOENT || ++count == 3)
+			return mbox_set_syscall_error(index, "stat()");
+
+		/* mbox was deleted by someone - happens with some MUAs
+		   when all mail is expunged. easiest way to deal with this
+		   is to recreate the file. */
+		fd = open(index->mbox_path, O_RDWR | O_CREAT | O_EXCL, 0660);
+		if (fd != -1)
+			(void)close(fd);
+		else if (errno != EEXIST)
+			return mbox_set_syscall_error(index, "open()");
+	}
 	filesize = st.st_size;
 
 	if (index->mbox_dev != st.st_dev || index->mbox_ino != st.st_ino) {




More information about the dovecot-cvs mailing list