From: Timo Sirainen Date: Thu, 28 Aug 2014 14:52:46 +0000 (+0900) Subject: Added UNLINK_EISDIR() helper macro. X-Git-Tag: 2.2.14.rc1~114 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaaa6e07cf961038cf030d623540a8296c0ffe24;p=thirdparty%2Fdovecot%2Fcore.git Added UNLINK_EISDIR() helper macro. --- diff --git a/src/lib-storage/index/maildir/maildir-sync-index.c b/src/lib-storage/index/maildir/maildir-sync-index.c index f2be00e220..dc34492918 100644 --- a/src/lib-storage/index/maildir/maildir-sync-index.c +++ b/src/lib-storage/index/maildir/maildir-sync-index.c @@ -95,7 +95,7 @@ static int maildir_expunge(struct maildir_mailbox *mbox, const char *path, } if (errno == ENOENT) return 0; - if (errno == EISDIR || errno == EPERM) + if (UNLINK_EISDIR(errno)) return maildir_lose_unexpected_dir(box->storage, path); mail_storage_set_critical(&mbox->storage->storage, diff --git a/src/lib-storage/list/mailbox-list-delete.c b/src/lib-storage/list/mailbox-list-delete.c index a295dceaae..b1a5368797 100644 --- a/src/lib-storage/list/mailbox-list-delete.c +++ b/src/lib-storage/list/mailbox-list-delete.c @@ -200,7 +200,7 @@ int mailbox_list_delete_mailbox_nonrecursive(struct mailbox_list *list, so don't bother stat()ing the file first */ if (unlink(str_c(full_path)) == 0) unlinked_something = TRUE; - else if (errno != ENOENT && errno != EISDIR && errno != EPERM) { + else if (errno != ENOENT && !UNLINK_EISDIR(errno)) { mailbox_list_set_critical(list, "unlink_directory(%s) failed: %m", str_c(full_path)); @@ -343,8 +343,7 @@ int mailbox_list_delete_symlink_default(struct mailbox_list *list, if (errno == ENOENT) { mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND, T_MAILBOX_LIST_ERR_NOT_FOUND(list, name)); - } else if (errno == EISDIR || - errno == EPERM) { /* Solaris */ + } else if (UNLINK_EISDIR(errno)) { mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE, "Mailbox isn't a symlink"); } else { diff --git a/src/lib/compat.h b/src/lib/compat.h index e13165620a..2abdee70bc 100644 --- a/src/lib/compat.h +++ b/src/lib/compat.h @@ -254,6 +254,11 @@ int i_my_clock_gettime(int clk_id, struct timespec *tp); #define ECANTLINK(errno) \ ((errno) == EXDEV || (errno) == EMLINK || (errno) == EPERM) +/* Returns TRUE if unlink() failed because it attempted to delete a directory */ +#define UNLINK_EISDIR(errno) \ + ((errno) == EPERM || /* POSIX */ \ + (errno) == EISDIR) /* Linux */ + /* EBUSY is given by some NFS implementations */ #define EDESTDIREXISTS(errno) \ ((errno) == EEXIST || (errno) == ENOTEMPTY || (errno) == EBUSY)