dovecot: If we can't delete the index or control directory, give...

dovecot at dovecot.org dovecot at dovecot.org
Sun Nov 18 11:18:49 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/337e6a9a2959
changeset: 6833:337e6a9a2959
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Nov 18 11:18:45 2007 +0200
description:
If we can't delete the index or control directory, give a nice error message
instead of internal error.

diffstat:

1 file changed, 20 insertions(+), 8 deletions(-)
src/lib-storage/mailbox-list.c |   28 ++++++++++++++++++++--------

diffs (53 lines):

diff -r ea4d3778c99b -r 337e6a9a2959 src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Sun Nov 18 10:56:21 2007 +0200
+++ b/src/lib-storage/mailbox-list.c	Sun Nov 18 11:18:45 2007 +0200
@@ -408,6 +408,24 @@ int mailbox_list_rename_mailbox(struct m
 	return list->v.rename_mailbox(list, oldname, newname);
 }
 
+static int mailbox_list_try_delete(struct mailbox_list *list, const char *dir)
+{
+	if (unlink_directory(dir, TRUE) == 0 || errno == ENOENT)
+		return 0;
+
+	if (errno == ENOTEMPTY) {
+		/* We're most likely using NFS and we can't delete
+		   .nfs* files. */
+		mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
+			"Mailbox is still open in another session, "
+			"can't delete it.");
+	} else {
+		mailbox_list_set_critical(list,
+			"unlink_directory(%s) failed: %m", dir);
+	}
+	return -1;
+}
+
 int mailbox_list_delete_index_control(struct mailbox_list *list,
 				      const char *name)
 {
@@ -421,22 +439,16 @@ int mailbox_list_delete_index_control(st
 	index_dir = mailbox_list_get_path(list, name,
 					  MAILBOX_LIST_PATH_TYPE_INDEX);
 	if (*index_dir != '\0' && strcmp(index_dir, path) != 0) {
-		if (unlink_directory(index_dir, TRUE) < 0 && errno != ENOENT) {
-			mailbox_list_set_critical(list,
-				"unlink_directory(%s) failed: %m", index_dir);
+		if (mailbox_list_try_delete(list, index_dir) < 0)
 			return -1;
-		}
 	}
 
 	/* control directory next */
 	dir = mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_CONTROL);
 	if (*dir != '\0' && strcmp(dir, path) != 0 &&
 	    strcmp(dir, index_dir) != 0) {
-		if (unlink_directory(dir, TRUE) < 0 && errno != ENOENT) {
-			mailbox_list_set_critical(list,
-				"unlink_directory(%s) failed: %m", dir);
+		if (mailbox_list_try_delete(list, index_dir) < 0)
 			return -1;
-		}
 	}
 	return 0;
 }


More information about the dovecot-cvs mailing list