From: Timo Sirainen Date: Tue, 8 Sep 2015 16:12:26 +0000 (+0300) Subject: lib-storage: Replaced some unlink()s with i_unlink*()s where we could. X-Git-Tag: 2.2.19.rc1~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=275cc4c040899c132b2acbe2fcac48ba4c1abbcf;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Replaced some unlink()s with i_unlink*()s where we could. This changes some mail_storage_set_critical() calls to i_error()s, but because these unlink() failures don't actually fail the operation it doesn't matter. --- diff --git a/src/lib-storage/index/cydir/cydir-save.c b/src/lib-storage/index/cydir/cydir-save.c index ca7316e805..063b59c0da 100644 --- a/src/lib-storage/index/cydir/cydir-save.c +++ b/src/lib-storage/index/cydir/cydir-save.c @@ -218,12 +218,8 @@ int cydir_save_finish(struct mail_save_context *_ctx) if (!ctx->failed) ctx->mail_count++; - else { - if (unlink(path) < 0) { - mail_storage_set_critical(&ctx->mbox->storage->storage, - "unlink(%s) failed: %m", path); - } - } + else + i_unlink(path); index_mail_cache_parse_deinit(_ctx->dest_mail, _ctx->data.received_date, !ctx->failed); diff --git a/src/lib-storage/index/cydir/cydir-sync.c b/src/lib-storage/index/cydir/cydir-sync.c index 9b005b8602..3e6122858b 100644 --- a/src/lib-storage/index/cydir/cydir-sync.c +++ b/src/lib-storage/index/cydir/cydir-sync.c @@ -41,16 +41,14 @@ cydir_sync_expunge(struct cydir_sync_context *ctx, uint32_t seq1, uint32_t seq2) str_truncate(ctx->path, ctx->path_dir_prefix_len); str_printfa(ctx->path, "%u.", uid); - if (unlink(str_c(ctx->path)) == 0) { + if (i_unlink_if_exists(str_c(ctx->path)) < 0) { + /* continue anyway */ + } else { if (box->v.sync_notify != NULL) { box->v.sync_notify(box, uid, MAILBOX_SYNC_TYPE_EXPUNGE); } mail_index_expunge(ctx->trans, seq1); - } else if (errno != ENOENT) { - mail_storage_set_critical(&ctx->mbox->storage->storage, - "unlink(%s) failed: %m", str_c(ctx->path)); - /* continue anyway */ } } } diff --git a/src/lib-storage/index/maildir/maildir-save.c b/src/lib-storage/index/maildir/maildir-save.c index ea3805cdca..6271af4e6a 100644 --- a/src/lib-storage/index/maildir/maildir-save.c +++ b/src/lib-storage/index/maildir/maildir-save.c @@ -624,10 +624,7 @@ static int maildir_save_finish_real(struct mail_save_context *_ctx) if (ctx->failed) { /* delete the tmp file */ - if (unlink(path) < 0 && errno != ENOENT) { - mail_storage_set_critical(storage, - "unlink(%s) failed: %m", path); - } + i_unlink_if_exists(path); errno = output_errno; if (ENOQUOTA(errno)) { diff --git a/src/lib-storage/index/maildir/maildir-sync.c b/src/lib-storage/index/maildir/maildir-sync.c index 8bf16aaa64..5dd6a933fa 100644 --- a/src/lib-storage/index/maildir/maildir-sync.c +++ b/src/lib-storage/index/maildir/maildir-sync.c @@ -325,13 +325,8 @@ static int maildir_fix_duplicate(struct maildir_sync_context *ctx, and hope that another process didn't just decide to unlink() the other (uidlist lock prevents this from happening) */ - if (unlink(path2) == 0) + if (i_unlink(path2) == 0) i_warning("Unlinked a duplicate: %s", path2); - else { - mail_storage_set_critical( - &ctx->mbox->storage->storage, - "unlink(%s) failed: %m", path2); - } } return 0; } diff --git a/src/lib-storage/index/maildir/maildir-uidlist.c b/src/lib-storage/index/maildir/maildir-uidlist.c index 71614985e1..19034e2746 100644 --- a/src/lib-storage/index/maildir/maildir-uidlist.c +++ b/src/lib-storage/index/maildir/maildir-uidlist.c @@ -1453,12 +1453,9 @@ static int maildir_uidlist_recreate(struct maildir_uidlist *uidlist) } } - if (ret < 0) { - if (unlink(temp_path) < 0) { - mail_storage_set_critical(box->storage, - "unlink(%s) failed: %m", temp_path); - } - } else if (fstat(fd, &st) < 0) { + if (ret < 0) + i_unlink(temp_path); + else if (fstat(fd, &st) < 0) { mail_storage_set_critical(box->storage, "fstat(%s) failed: %m", temp_path); ret = -1;