[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-storage.c, 1.115.2.14, 1.115.2.15

tss at dovecot.org tss at dovecot.org
Fri Dec 15 22:52:11 UTC 2006


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

Modified Files:
      Tag: branch_1_0
	maildir-storage.c 
Log Message:
rename and delete operations didn't touch control directory if it was
different from maildir or index dir.



Index: maildir-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.c,v
retrieving revision 1.115.2.14
retrieving revision 1.115.2.15
diff -u -d -r1.115.2.14 -r1.115.2.15
--- maildir-storage.c	3 Dec 2006 13:29:55 -0000	1.115.2.14
+++ maildir-storage.c	15 Dec 2006 22:52:09 -0000	1.115.2.15
@@ -696,9 +696,10 @@
 static int maildir_mailbox_delete(struct mail_storage *_storage,
 				  const char *name)
 {
-	struct index_storage *storage = (struct index_storage *)_storage;
+	struct maildir_storage *mstorage = (struct maildir_storage *)_storage;
+	struct index_storage *storage = &mstorage->storage;
 	struct stat st;
-	const char *src, *dest, *index_dir;
+	const char *src, *dest, *index_dir, *control_dir;
 	int count;
 
 	mail_storage_clear_error(_storage);
@@ -730,7 +731,7 @@
 	   can't really help that. */
 	index_storage_destroy_unrefed();
 
-	if (storage->index_dir != NULL && *name != '/' && *name != '~' &&
+	if (storage->index_dir != NULL && dest != NULL &&
 	    strcmp(storage->index_dir, storage->dir) != 0) {
 		index_dir = t_strconcat(storage->index_dir,
 					"/"MAILDIR_FS_SEP_S, name, NULL);
@@ -741,6 +742,19 @@
 			return -1;
 		}
 	}
+	if (mstorage->control_dir != NULL && dest != NULL &&
+	    strcmp(mstorage->control_dir, storage->dir) != 0 &&
+	    (storage->index_dir == NULL ||
+	     strcmp(storage->index_dir, mstorage->control_dir) != 0)) {
+		control_dir = t_strconcat(mstorage->control_dir,
+					  "/"MAILDIR_FS_SEP_S, name, NULL);
+		if (unlink_directory(control_dir, TRUE) < 0 &&
+		    errno != ENOTEMPTY) {
+			mail_storage_set_critical(_storage,
+				"unlink_directory(%s) failed: %m", control_dir);
+			return -1;
+		}
+	}
 
 	if (dest == NULL) {
 		/* absolute maildir path, delete the directory directly
@@ -779,6 +793,31 @@
 	return 0;
 }
 
+static int rename_control(struct index_storage *istorage,
+			  const char *oldname, const char *newname)
+{
+	struct maildir_storage *storage = (struct maildir_storage *)istorage;
+	const char *oldpath, *newpath;
+
+	if (storage->control_dir == NULL ||
+	    strcmp(storage->control_dir, istorage->dir) == 0)
+		return 0;
+
+	oldpath = t_strconcat(storage->control_dir, "/"MAILDIR_FS_SEP_S,
+			      oldname, NULL);
+	newpath = t_strconcat(storage->control_dir, "/"MAILDIR_FS_SEP_S,
+			      newname, NULL);
+
+	if (rename(oldpath, newpath) < 0 && errno != ENOENT) {
+		mail_storage_set_critical(&istorage->storage,
+					  "rename(%s, %s) failed: %m",
+					  oldpath, newpath);
+		return -1;
+	}
+
+	return 0;
+}
+
 static int rename_indexes(struct index_storage *storage,
 			  const char *oldname, const char *newname)
 {
@@ -872,6 +911,7 @@
 			break;
 		}
 
+		(void)rename_control(storage, old_listname, new_listname);
 		(void)rename_indexes(storage, old_listname, new_listname);
 		t_pop();
 	}
@@ -910,6 +950,7 @@
 
 	ret = rename(oldpath, newpath);
 	if (ret == 0 || errno == ENOENT) {
+		(void)rename_control(storage, oldname, newname);
 		(void)rename_indexes(storage, oldname, newname);
 
 		found = ret == 0;



More information about the dovecot-cvs mailing list