Mercurial > dovecot > original-hg > dovecot-1.2
changeset 828:774f32498a7f HEAD
We couldn't delete mbox folders.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 21 Dec 2002 15:51:55 +0200 |
parents | 0450b8c216e8 |
children | 56bbee9df6f4 |
files | src/lib-storage/index/mbox/mbox-storage.c |
diffstat | 1 files changed, 33 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-storage.c Sat Dec 21 15:38:00 2002 +0200 +++ b/src/lib-storage/index/mbox/mbox-storage.c Sat Dec 21 15:51:55 2002 +0200 @@ -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; } + path = mbox_get_path(storage, name); + 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, "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 */ - path = mbox_get_path(storage, name); - if (unlink(path) == -1) { + if (unlink(path) < 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 " - "%s: %m", path); + "unlink() failed for %s: %m", + path); } return FALSE; }