From: Timo Sirainen Date: Tue, 8 Sep 2015 16:11:45 +0000 (+0300) Subject: lib-index: Replaced some unlink()s with i_unlink*()s where we could. X-Git-Tag: 2.2.19.rc1~57 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=39087f589d24f3072f220c2ed4528ee323f129ff;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Replaced some unlink()s with i_unlink*()s where we could. This changes some mail_index_set_error() calls to i_error()s, but because these unlink() failures don't actually fail the operation it doesn't matter. In fact it may be even better that it doesn't overwrite the existing index->error if it exists. --- diff --git a/src/lib-index/mail-index-write.c b/src/lib-index/mail-index-write.c index 8e8ebfa672..e8eb7c06ed 100644 --- a/src/lib-index/mail-index-write.c +++ b/src/lib-index/mail-index-write.c @@ -110,12 +110,8 @@ static int mail_index_recreate(struct mail_index *index) ret = -1; } - if (ret < 0) { - if (unlink(path) < 0) { - mail_index_set_error(index, "unlink(%s) failed: %m", - path); - } - } + if (ret < 0) + i_unlink(path); return ret; } diff --git a/src/lib-index/mail-transaction-log-file.c b/src/lib-index/mail-transaction-log-file.c index ce17450108..eea8e59a62 100644 --- a/src/lib-index/mail-transaction-log-file.c +++ b/src/lib-index/mail-transaction-log-file.c @@ -794,9 +794,7 @@ mail_transaction_log_file_create2(struct mail_transaction_log_file *file, file_dotlock_replace(). during that time the log file doesn't exist, which could cause problems. */ path2 = t_strconcat(file->filepath, ".2", NULL); - if (unlink(path2) < 0 && errno != ENOENT) { - mail_index_set_error(index, "unlink(%s) failed: %m", - path2); + if (i_unlink_if_exists(path2) < 0) { /* try to link() anyway */ } if (nfs_safe_link(file->filepath, path2, FALSE) < 0 && @@ -916,11 +914,8 @@ int mail_transaction_log_file_open(struct mail_transaction_log_file *file) /* corrupted */ if (index->readonly) { /* don't delete */ - } else if (unlink(file->filepath) < 0 && - errno != ENOENT) { - mail_index_set_error(index, - "unlink(%s) failed: %m", - file->filepath); + } else { + i_unlink_if_exists(file->filepath); } return 0; } diff --git a/src/lib-index/mail-transaction-log.c b/src/lib-index/mail-transaction-log.c index e5a6d26ce4..d7da173533 100644 --- a/src/lib-index/mail-transaction-log.c +++ b/src/lib-index/mail-transaction-log.c @@ -52,12 +52,8 @@ static void mail_transaction_log_2_unlink_old(struct mail_transaction_log *log) } if (st.st_mtime + MAIL_TRANSACTION_LOG2_STALE_SECS <= ioloop_time && - !log->index->readonly) { - if (unlink(log->filepath2) < 0 && errno != ENOENT) { - mail_index_set_error(log->index, - "unlink(%s) failed: %m", log->filepath2); - } - } + !log->index->readonly) + i_unlink_if_exists(log->filepath2); } int mail_transaction_log_open(struct mail_transaction_log *log)