[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-storage.c,1.25,1.26

cras at procontrol.fi cras at procontrol.fi
Sat Dec 21 15:51:57 EET 2002


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

Modified Files:
	mbox-storage.c 
Log Message:
We couldn't delete mbox folders.



Index: mbox-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mbox-storage.c	21 Dec 2002 12:13:58 -0000	1.25
+++ mbox-storage.c	21 Dec 2002 13:51:55 -0000	1.26
@@ -332,6 +332,7 @@
 static int mbox_delete_mailbox(MailStorage *storage, const char *name)
 {
 	const char *index_dir, *path;
+	struct stat st;
 
 	mail_storage_clear_error(storage);
 
@@ -345,17 +346,45 @@
 		return FALSE;
 	}
 
-	/* first unlink the mbox file */
 	path = mbox_get_path(storage, name);
-	if (unlink(path) == -1) {
+	if (lstat(path, &st) < 0) {
 		if (errno == ENOENT) {
 			mail_storage_set_error(storage,
 					       "Mailbox doesn't exist: %s",
 					       name);
 		} else {
-			mail_storage_set_critical(storage,
-						  "Can't delete mbox file "
+			mail_storage_set_critical(storage, "lstat() failed for "
 						  "%s: %m", path);
+		}
+		return FALSE;
+	}
+
+	if (S_ISDIR(st.st_mode)) {
+		/* deleting a folder, only allow it if it's empty */
+		if (rmdir(path) == 0)
+			return TRUE;
+
+		if (errno == ENOTEMPTY) {
+			mail_storage_set_error(storage, "Folder %s "
+					       "isn't empty, can't delete it.",
+					       name);
+		} else {
+			mail_storage_set_critical(storage, "rmdir() failed for "
+						  "%s: %m", path);
+		}
+		return FALSE;
+	}
+
+	/* first unlink the mbox file */
+	if (unlink(path) < 0) {
+		if (errno == ENOENT) {
+			mail_storage_set_error(storage,
+					       "Mailbox doesn't exist: %s",
+					       name);
+		} else {
+			mail_storage_set_critical(storage,
+						  "unlink() failed for %s: %m",
+						  path);
 		}
 		return FALSE;
 	}




More information about the dovecot-cvs mailing list