changeset 5622:5f14caa1ed9b HEAD

Handle symlinks pointing to nonexisting files better.
author Timo Sirainen <tss@iki.fi>
date Tue, 15 May 2007 13:21:00 +0300
parents eba408782747
children e41accd3d6f1
files src/lib-storage/index/maildir/maildir-util.c
diffstat 1 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-util.c	Mon May 14 02:03:07 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-util.c	Tue May 15 13:21:00 2007 +0300
@@ -43,6 +43,23 @@
 	return ret;
 }
 
+static int do_racecheck(struct maildir_mailbox *mbox, const char *path,
+			void *context __attr_unused__)
+{
+	struct stat st;
+
+	if (lstat(path, &st) == 0 && (st.st_mode & S_IFLNK) != 0) {
+		/* most likely a symlink pointing to a non-existing file */
+		mail_storage_set_critical(&mbox->storage->storage,
+			"Maildir: Symlink destination doesn't exist: %s", path);
+		return -2;
+	} else {
+		mail_storage_set_critical(&mbox->storage->storage,
+			"maildir_file_do(%s): Filename keeps changing", path);
+		return -1;
+	}
+}
+
 #undef maildir_file_do
 int maildir_file_do(struct maildir_mailbox *mbox, uint32_t uid,
 		    maildir_file_do_func *callback, void *context)
@@ -60,11 +77,8 @@
 		ret = maildir_file_do_try(mbox, uid, callback, context);
 	}
 
-	if (i == 10) {
-		ret = -1;
-		mail_storage_set_critical(&mbox->storage->storage,
-			"maildir_file_do(%s) racing", mbox->path);
-	}
+	if (i == 10)
+		ret = maildir_file_do_try(mbox, uid, do_racecheck, context);
 
 	return ret == -2 ? 0 : ret;
 }