]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Replaced unlink() calls with i_unlink*() wherever possible.
authorTimo Sirainen <tss@iki.fi>
Tue, 8 Sep 2015 16:07:02 +0000 (19:07 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 8 Sep 2015 16:07:02 +0000 (19:07 +0300)
54 files changed:
src/auth/auth-token.c
src/doveadm/doveadm-sis.c
src/doveadm/dsync/dsync-brain.c
src/doveadm/dsync/dsync-ibc-stream.c
src/lda/main.c
src/lib-compression/test-compression.c
src/lib-fs/fs-posix.c
src/lib-imap-client/imapc-client.c
src/lib-imap-urlauth/imap-urlauth-connection.c
src/lib-index/mail-cache-compress.c
src/lib-index/mail-cache.c
src/lib-index/mail-index-strmap.c
src/lib-index/mail-index-transaction.c
src/lib-index/mail-index.c
src/lib-index/mailbox-log.c
src/lib-index/test-mail-transaction-log-append.c
src/lib-lda/duplicate.c
src/lib-lda/smtp-client.c
src/lib-mail/test-istream-attachment.c
src/lib-master/mountpoint-list.c
src/lib-storage/index/dbox-common/dbox-file-fix.c
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/index/dbox-single/sdbox-file.c
src/lib-storage/index/index-mail-binary.c
src/lib-storage/index/maildir/maildir-keywords.c
src/lib-storage/index/maildir/maildir-save.c
src/lib-storage/index/maildir/maildir-uidlist.c
src/lib-storage/index/pop3c/pop3c-client.c
src/lib-storage/mailbox-uidvalidity.c
src/lib/file-copy.c
src/lib/file-create-locked.c
src/lib/file-dotlock.c
src/lib/iostream-rawlog.c
src/lib/iostream-temp.c
src/lib/istream-seekable.c
src/lib/net.c
src/lib/safe-mkstemp.c
src/lib/test-istream-seekable.c
src/lib/test-ostream-file.c
src/lib/unlink-old-files.c
src/lmtp/commands.c
src/login-common/ssl-proxy-gnutls.c
src/master/main.c
src/master/master-settings.c
src/master/service-listen.c
src/plugins/acl/acl-backend-vfile-acllist.c
src/plugins/fts-squat/squat-test.c
src/plugins/fts-squat/squat-trie.c
src/plugins/fts-squat/squat-uidlist.c
src/plugins/fts/fts-expunge-log.c
src/plugins/mail-filter/mail-filter-plugin.c
src/plugins/quota/quota-maildir.c
src/ssl-params/ssl-params.c

index aad17d4b6599cea76d79ee8dddac1d0b595b6c4a..1746377289ea42b5b3c0f1ae240868b8fa13d72e 100644 (file)
@@ -57,8 +57,7 @@ auth_token_read_secret(const char *path,
        if (st.st_size != AUTH_TOKEN_SECRET_LEN || !S_ISREG(st.st_mode)) {
                i_error("Corrupted token secret file: %s", path);
                i_close_fd(&fd);
-               if (unlink(path) < 0)
-                       i_error("unlink(%s) failed: %m", path);
+               i_unlink(path);
                return -1;
        }
 
@@ -76,8 +75,7 @@ auth_token_read_secret(const char *path,
            !CMP_DEV_T(st.st_dev, lst.st_dev)) {
                i_error("Compromised token secret file: %s", path);
                i_close_fd(&fd);
-               if (unlink(path) < 0)
-                       i_error("unlink(%s) failed: %m", path);
+               i_unlink(path);
                return -1;
        }
 
@@ -126,15 +124,13 @@ auth_token_write_secret(const char *path,
        }
 
        if (ret < 0) {
-               if (unlink(temp_path) < 0)
-                       i_error("unlink(%s) failed: %m", temp_path);
+               i_unlink(temp_path);
                return -1;
        }
 
        if (rename(temp_path, path) < 0) {
                i_error("rename(%s, %s) failed: %m", temp_path, path);
-               if (unlink(temp_path) < 0)
-                       i_error("unlink(%s) failed: %m", temp_path);
+               i_unlink(temp_path);
                return -1;
        }
 
index 08dcfdbad1fc4322d4ced1566ba131435f526408..e5534a564f19be29a71faa8bc2239d584b41391b 100644 (file)
@@ -118,14 +118,12 @@ hardlink_replace(const char *src, const char *dest, ino_t src_inode)
                return -1;
        }
        if (st.st_ino != src_inode) {
-               if (unlink(tmppath) < 0)
-                       i_error("unlink(%s) failed: %m", tmppath);
+               i_unlink(tmppath);
                return 0;
        }
        if (rename(tmppath, dest) < 0) {
                i_error("rename(%s, %s) failed: %m", src, tmppath);
-               if (unlink(tmppath) < 0)
-                       i_error("unlink(%s) failed: %m", tmppath);
+               i_unlink(tmppath);
                return -1;
        }
        return 1;
@@ -258,10 +256,8 @@ static void cmd_sis_deduplicate(int argc, char *argv[])
                T_BEGIN {
                        ret = sis_try_deduplicate(rootdir, d->d_name);
                } T_END;
-               if (ret == 0) {
-                       if (unlink(str_c(path)) < 0)
-                               i_error("unlink(%s) failed: %m", str_c(path));
-               }
+               if (ret == 0)
+                       i_unlink(str_c(path));
        }
        if (closedir(dir) < 0)
                i_error("closedir(%s) failed: %m", queuedir);
index 0c91dd850e6db9d8f21ded0c602ad04eebc41a7d..b89db0e6d74dfece2eb68952393bd9aa18bf2cb0 100644 (file)
@@ -332,8 +332,7 @@ int dsync_brain_deinit(struct dsync_brain **_brain, enum mail_error *error_r)
 
        if (brain->lock_fd != -1) {
                /* unlink the lock file before it gets unlocked */
-               if (unlink(brain->lock_path) < 0)
-                       i_error("unlink(%s) failed: %m", brain->lock_path);
+               i_unlink(brain->lock_path);
                file_lock_free(&brain->lock);
                i_close_fd(&brain->lock_fd);
        }
index 2d55edb3060a33051a4a01200af31a600695f0a3..8446d8b64687c843ded086633c7d6163af86a74d 100644 (file)
@@ -467,9 +467,8 @@ static int seekable_fd_callback(const char **path_r, void *context)
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index 2e1a0ffdc6ef93c9bf3cc481c647aaa7bcc9987c..bfca341bc1fa36c3b08e7328f7ffa4238d743006 100644 (file)
@@ -98,9 +98,8 @@ static int seekable_fd_callback(const char **path_r, void *context)
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index 2a6033b3b577058d0a416a7aa9e49262660ade3e..ef902a102092f3424e9520da7b127d175c2fa517 100644 (file)
@@ -80,8 +80,7 @@ static void test_compression_handler(const struct compression_handler *handler)
        sha1_result(&sha1, input_sha1);
 
        test_assert(memcmp(input_sha1, output_sha1, sizeof(input_sha1)) == 0);
-       if (unlink(path) < 0)
-               i_error("unlink(%s) failed: %m", path);
+       i_unlink(path);
 
        test_end();
 }
index 84dd98081538935181a4aabc7eb6e02a7fce2a84..af2f333580d5ba117b927ed3c1fb5cf36f553a16 100644 (file)
@@ -630,8 +630,7 @@ static int fs_posix_copy(struct fs_file *_src, struct fs_file *_dest)
        ret = link(src->full_path, dest->full_path);
        if (errno == EEXIST && dest->open_mode == FS_OPEN_MODE_REPLACE) {
                /* destination file already exists - replace it */
-               if (unlink(dest->full_path) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", dest->full_path);
+               i_unlink_if_exists(dest->full_path);
                ret = link(src->full_path, dest->full_path);
        }
        while (ret < 0 && errno == ENOENT &&
index 2f9aa21c92b99b084a3e0542aa6012278fd5515c..4693af7b73cba3dc781c72e3420a416af25f3705 100644 (file)
@@ -460,9 +460,8 @@ int imapc_client_create_temp_fd(struct imapc_client *client,
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index 66f26b1d5eb546b50c79846b9274229258ceecc4..b93adc93811a77656f62620a921d6834ffb59f09 100644 (file)
@@ -493,9 +493,8 @@ imap_urlauth_connection_create_temp_fd(struct imap_urlauth_connection *conn,
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index c2064bd7ca15b3f4975bf2e39b31b58b4e23455a..7cc5ddb58ccc82f7f629431f910b9946dbfdad30 100644 (file)
@@ -458,8 +458,7 @@ static int mail_cache_compress_locked(struct mail_cache *cache,
                return -1;
        if (mail_cache_compress_write(cache, trans, fd, temp_path, unlock) < 0) {
                i_close_fd(&fd);
-               if (unlink(temp_path) < 0)
-                       i_error("unlink(%s) failed: %m", temp_path);
+               i_unlink(temp_path);
                return -1;
        }
        if (cache->file_cache != NULL)
index 36afcac5c68e031da29e935985ac52557a239adf..d85d397b668d005f5d7bbb0a1fd6894280bea5f4 100644 (file)
@@ -25,7 +25,7 @@ void mail_cache_set_syscall_error(struct mail_cache *cache,
 static void mail_cache_unlink(struct mail_cache *cache)
 {
        if (!cache->index->readonly)
-               (void)unlink(cache->filepath);
+               i_unlink(cache->filepath);
 }
 
 void mail_cache_reset(struct mail_cache *cache)
index bc53303597cd5a882e9d45d8bc3e89d034b127c9..2dc2f7a104d377439caa7a01366782285f250c7e 100644 (file)
@@ -243,7 +243,7 @@ void mail_index_strmap_view_set_corrupted(struct mail_index_strmap_view *view)
        mail_index_set_error(view->strmap->index,
                             "Corrupted strmap index file: %s",
                             view->strmap->path);
-       (void)unlink(view->strmap->path);
+       i_unlink(view->strmap->path);
        mail_index_strmap_close(view->strmap);
        mail_index_strmap_view_reset(view);
 }
@@ -285,7 +285,7 @@ static int mail_index_strmap_open(struct mail_index_strmap_view *view)
            hdr.uid_validity != idx_hdr->uid_validity) {
                /* need to rebuild. if we already had something in the strmap,
                   we can keep it. */
-               (void)unlink(strmap->path);
+               i_unlink(strmap->path);
                mail_index_strmap_close(strmap);
                return 0;
        }
@@ -1034,7 +1034,7 @@ static int mail_index_strmap_recreate(struct mail_index_strmap_view *view)
                ret = -1;
        }
        if (ret < 0)
-               (void)unlink(temp_path);
+               i_unlink(temp_path);
        return ret;
 }
 
index 8c1dc36f0c0e8fe35eb0e12c61e8f7aac48f5817..2f842601a1e3d3e867a5d6342177cae0b7deaf2a 100644 (file)
@@ -176,8 +176,7 @@ mail_index_transaction_commit_real(struct mail_index_transaction *t,
        if (t->reset) {
                /* get rid of the old index. it might just confuse readers,
                   especially if it's broken. */
-               if (unlink(log->index->filepath) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", log->index->filepath);
+               i_unlink_if_exists(log->index->filepath);
        }
 
        *commit_size_r = log_offset2 - log_offset1;
index 4b9d4b4c1df3d3911a830cb27f9471ffe84fcfc8..9d656c1867ede3167b6f1de83c8f5102d8dab6fe 100644 (file)
@@ -468,10 +468,8 @@ int mail_index_create_tmp_file(struct mail_index *index,
        if (fd == -1 && errno == EEXIST) {
                /* stale temp file. unlink and recreate rather than overwriting,
                   just to make sure locking problems won't cause corruption */
-               if (unlink(path) < 0) {
-                       i_error("unlink(%s) failed: %m", path);
+               if (i_unlink(path) < 0)
                        return -1;
-               }
                old_mask = umask(0);
                fd = open(path, O_RDWR|O_CREAT|O_EXCL, index->mode);
                umask(old_mask);
index 539e4329427942f8d1bf363d2394f70af267969f..43b8d9e700e1ab27bf04dd4a7d2b3ab7df532c58 100644 (file)
@@ -276,8 +276,7 @@ mailbox_log_iter_next(struct mailbox_log_iter *iter)
                        (iter->count - iter->idx) * sizeof(iter->buf[0]);
                i_error("Corrupted mailbox log %s at offset %"PRIuUOFF_T": "
                        "type=%d", iter->filepath, offset, rec->type);
-               if (unlink(iter->filepath) < 0)
-                       i_error("unlink(%s) failed: %m", iter->filepath);
+               i_unlink(iter->filepath);
                return NULL;
        }
        return rec;
index cbfbe15c88bd68b589bfcf755d308fe1ad3fb9d1..dacea92d9e5b3f3e08ae507ef956fc9252dd9288 100644 (file)
@@ -162,7 +162,7 @@ static void test_mail_transaction_log_append(void)
        i_free(log->head);
        i_free(log->index);
        i_free(log);
-       unlink(tmp_path);
+       i_unlink(tmp_path);
 }
 
 int main(void)
index 86849f91fad977b2b153db56e4a5302696e5fe2d..40a1aeb58c5d9095adbd3f9502d5a7a7cc8ebd14 100644 (file)
@@ -184,10 +184,8 @@ static int duplicate_read(struct duplicate_file *file)
        }
 
        if (record_size == 0 ||
-           duplicate_read_records(file, input, record_size) < 0) {
-               if (unlink(file->path) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", file->path);
-       }
+           duplicate_read_records(file, input, record_size) < 0)
+               i_unlink_if_exists(file->path);
 
        i_stream_unref(&input);
        if (close(fd) < 0)
index f73cf8b21102030b66c59bec9fa2de905ec46c7b..881f55617d057e6209069491e14418db4388538a 100644 (file)
@@ -87,9 +87,8 @@ static int create_temp_file(const char **path_r)
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index a7fdd9173cac7ca989073858781e080b9904f78a..fdb21acc7f86cf71a247fea96dd71e628a671755 100644 (file)
@@ -132,7 +132,7 @@ static int test_open_temp_fd(void *context ATTR_UNUSED)
        fd = safe_mkstemp(str, 0600, (uid_t)-1, (gid_t)-1);
        if (fd == -1)
                i_fatal("safe_mkstemp(%s) failed: %m", str_c(str));
-       (void)unlink(str_c(str));
+       i_unlink(str_c(str));
        return fd;
 }
 
index b120626956d3e8935410a115513d7a1e8b7bae85..1de0579c4f118f73a8b12a6c7f439700a9cfe1d3 100644 (file)
@@ -223,7 +223,7 @@ mountpoint_list_save_to(struct mountpoint_list *list, const char *path)
        } else {
                return 0;
        }
-       (void)unlink(str_c(temp_path));
+       i_unlink(str_c(temp_path));
        return -1;
 }
 
index accfa7f38fe1b250bf2d4fc0dc88b3f918f14a35..d28f5059ab2735b3f65c5d1b13f24e690b190845 100644 (file)
@@ -498,10 +498,8 @@ int dbox_file_fix(struct dbox_file *file, uoff_t start_offset)
        if (!have_messages) {
                /* the resulting file has no messages. just delete the file. */
                dbox_file_close(file);
-               if (unlink(temp_path) < 0)
-                       i_error("unlink(%s) failed: %m", temp_path);
-               if (unlink(file->cur_path) < 0)
-                       i_error("unlink(%s) failed: %m", file->cur_path);
+               i_unlink(temp_path);
+               i_unlink(file->cur_path);
                return 0;
        }
        if (rename(temp_path, file->cur_path) < 0) {
index 92b5cfe5ec1b22f0adb42694cd89af875d8b4ec2..04435786e33b73a20b07fc5a2cd80b4feba1f51a 100644 (file)
@@ -77,8 +77,7 @@ static void dbox_verify_alt_path(struct mailbox_list *list)
                return;
 
        /* unlink/create the current alt path symlink */
-       if (unlink(alt_symlink_path) < 0 && errno != ENOENT)
-               i_error("unlink(%s) failed: %m", alt_symlink_path);
+       i_unlink_if_exists(alt_symlink_path);
        if (alt_path != NULL) {
                if (symlink(alt_path, alt_symlink_path) < 0 &&
                    errno != EEXIST) {
index 3ccc15b956828da07ed2d1732b24b9f4d985c4ff..2798f5bbe1828d61512ee3bd3bc44b4ba3fc8763 100644 (file)
@@ -249,8 +249,7 @@ rebuild_rename_file(struct mdbox_storage_rebuild_context *ctx,
                /* use link()+unlink() instead of rename() to make sure we
                   don't overwrite any files. */
                if (link(old_path, new_path) == 0) {
-                       if (unlink(old_path) < 0)
-                               i_error("unlink(%s) failed: %m", old_path);
+                       i_unlink(old_path);
                        *fname_p = strrchr(new_path, '/') + 1;
                        *file_id_r = ctx->highest_file_id;
                        return 0;
index 7ae0cc991f06c122e48c251ed0c823fb8b7b4450..d4f135ff49edf2933f4c059ddc5cdea1dc6dbcd4 100644 (file)
@@ -352,7 +352,7 @@ int sdbox_file_move(struct dbox_file *file, bool alt_path)
                ret = -1;
        }
        if (ret < 0) {
-               (void)unlink(temp_path);
+               i_unlink(temp_path);
                return -1;
        }
        /* preserve the original atime/mtime. this isn't necessary for Dovecot,
@@ -370,14 +370,14 @@ int sdbox_file_move(struct dbox_file *file, bool alt_path)
        if (rename(temp_path, dest_path) < 0) {
                mail_storage_set_critical(storage,
                        "rename(%s, %s) failed: %m", temp_path, dest_path);
-               (void)unlink(temp_path);
+               i_unlink_if_exists(temp_path);
                return -1;
        }
        if (storage->set->parsed_fsync_mode != FSYNC_MODE_NEVER) {
                if (fdatasync_path(dest_dir) < 0) {
                        mail_storage_set_critical(storage,
                                "fdatasync(%s) failed: %m", dest_dir);
-                       (void)unlink(dest_path);
+                       i_unlink(dest_path);
                        return -1;
                }
        }
@@ -385,7 +385,7 @@ int sdbox_file_move(struct dbox_file *file, bool alt_path)
                dbox_file_set_syscall_error(file, "unlink()");
                if (errno == EACCES) {
                        /* configuration problem? revert the write */
-                       (void)unlink(dest_path);
+                       i_unlink(dest_path);
                }
                /* who knows what happened to the file. keep both just to be
                   sure both won't get deleted. */
index 2a6dd91a93e34ee1d1b6976d8dcafa29343209f6..0e61369e165227629de813ba2d472e85f2c80872 100644 (file)
@@ -220,9 +220,8 @@ static int fd_callback(const char **path_r, void *context)
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index 126c57492628be71a458053abbe70eb60717542e..315aa51179ce97ea7e90814b2836e885c110f3ac 100644 (file)
@@ -365,7 +365,7 @@ static int maildir_keywords_commit(struct maildir_keywords *mk)
                return 0;
 
        lock_path = t_strconcat(mk->path, ".lock", NULL);
-       (void)unlink(lock_path);
+       i_unlink_if_exists(lock_path);
 
        perm = mailbox_get_permissions(&mk->mbox->box);
        for (i = 0;; i++) {
index 9790fff05cd41aec2e2896a54a2f9de2807dbc3b..ea3805cdca769e5e4554e16c6a0c4ae661fad897 100644 (file)
@@ -671,7 +671,7 @@ maildir_save_unlink_files(struct maildir_save_context *ctx)
        struct maildir_filename *mf;
 
        for (mf = ctx->files; mf != NULL; mf = mf->next) T_BEGIN {
-               (void)unlink(maildir_mf_get_path(ctx, mf));
+               i_unlink(maildir_mf_get_path(ctx, mf));
        } T_END;
        ctx->files = NULL;
 }
index a8553e7948e21a29211fcece872dfa82b52070bb..71614985e19afce9798532087d013bbc08f87b25 100644 (file)
@@ -817,7 +817,7 @@ maildir_uidlist_update_read(struct maildir_uidlist *uidlist,
 
         if (ret == 0) {
                 /* file is broken */
-                (void)unlink(uidlist->path);
+                i_unlink(uidlist->path);
         } else if (ret > 0) {
                 /* success */
                if (readonly)
index 1d9356ab9d230bd6ef7f6fe086959dd3162bcaee..0226bbc242895ada5e638289759a51219da06c15 100644 (file)
@@ -753,9 +753,8 @@ static int seekable_fd_callback(const char **path_r, void *context)
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index 705e70f715ca543d12cbc923d3411fe713be1c47..055b3ea4ff8b1753efa52371520d2635b904b053 100644 (file)
@@ -181,8 +181,7 @@ mailbox_uidvalidity_next_rescan(struct mailbox_list *list, const char *path)
        if (min_value != max_value) {
                /* duplicate uidvalidity files, delete the oldest */
                tmp = t_strdup_printf("%s.%08x", path, min_value);
-               if (unlink(tmp) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", tmp);
+               i_unlink_if_exists(tmp);
        }
 
        cur_value = max_value;
index 7eddbcb54627137af810d226909f429e1a97200f..4665ce90a06a64b8c20c07b6d7238f5de24fb478 100644 (file)
@@ -25,10 +25,8 @@ static int file_copy_to_tmp(const char *srcpath, const char *tmppath,
                if (link(srcpath, tmppath) == 0)
                        return 1;
                if (errno == EEXIST) {
-                       if (unlink(tmppath) < 0 && errno != ENOENT) {
-                               i_error("unlink(%s) failed: %m", tmppath);
+                       if (i_unlink_if_exists(tmppath) < 0)
                                return -1;
-                       }
                        if (link(srcpath, tmppath) == 0)
                                return 1;
                }
@@ -109,7 +107,7 @@ int file_copy(const char *srcpath, const char *destpath, bool try_hardlink)
                        }
                }
                if (ret < 0)
-                       (void)unlink(tmppath);
+                       i_unlink(tmppath);
        } T_END;
        return ret;
 }
index f9efda5b584d549db3055e47ae0855c357478e9f..0c78eacebed10eef73c52008e35e5a33e5f6009c 100644 (file)
@@ -77,15 +77,13 @@ try_create_new(const char *path, const struct file_create_settings *set,
                                                   str_c(temp_path), path);
                }
        } else {
-               if (unlink(str_c(temp_path)) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", str_c(temp_path));
+               i_unlink_if_exists(str_c(temp_path));
                *fd_r = fd;
                return 1;
        }
        orig_errno = errno;
        i_close_fd(&fd);
-       if (unlink(str_c(temp_path)) < 0 && errno != ENOENT)
-               i_error("unlink(%s) failed: %m", str_c(temp_path));
+       i_unlink_if_exists(str_c(temp_path));
        errno = orig_errno;
        return ret;
 }
index 2c7e3053cdd75db86cc06ade90a6c526d8330b14..2e1eb810d4933a4cf3508f200ad01d98dc5a3f0b 100644 (file)
@@ -191,11 +191,8 @@ static int update_lock_info(time_t now, struct lock_info *lock_info,
 
 static int dotlock_override(struct lock_info *lock_info)
 {
-       if (unlink(lock_info->lock_path) < 0 && errno != ENOENT) {
-               i_error("unlink(%s) failed: %m",
-                       lock_info->lock_path);
+       if (i_unlink_if_exists(lock_info->lock_path) < 0)
                return -1;
-       }
 
        /* make sure we sleep for a while after overriding the lock file.
           otherwise another process might try to override it at the same time
@@ -391,8 +388,7 @@ static int try_create_lock_hardlink(struct lock_info *lock_info, bool write_pid,
                return -1;
        }
 
-       if (unlink(lock_info->temp_path) < 0) {
-               i_error("unlink(%s) failed: %m", lock_info->temp_path);
+       if (i_unlink(lock_info->temp_path) < 0) {
                /* non-fatal, continue */
        }
        lock_info->temp_path = NULL;
@@ -596,10 +592,8 @@ dotlock_create(struct dotlock *dotlock, enum dotlock_create_flags flags,
                        i_error("close(%s) failed: %m", lock_path);
                errno = old_errno;
        }
-       if (lock_info.temp_path != NULL) {
-               if (unlink(lock_info.temp_path) < 0)
-                       i_error("unlink(%s) failed: %m", lock_info.temp_path);
-       }
+       if (lock_info.temp_path != NULL)
+               i_unlink(lock_info.temp_path);
 
        if (ret == 0)
                errno = EAGAIN;
@@ -724,6 +718,7 @@ int file_dotlock_delete(struct dotlock **dotlock_p)
        struct dotlock *dotlock;
        const char *lock_path;
         struct stat st;
+       int ret;
 
        dotlock = *dotlock_p;
        *dotlock_p = NULL;
@@ -758,20 +753,10 @@ int file_dotlock_delete(struct dotlock **dotlock_p)
                          (int)(time(NULL) - dotlock->lock_time));
        }
 
-       if (unlink(lock_path) < 0) {
-               if (errno == ENOENT) {
-                       dotlock_replaced_warning(dotlock, TRUE);
-                       file_dotlock_free(&dotlock);
-                       return 0;
-               }
-
-               i_error("unlink(%s) failed: %m", lock_path);
-               file_dotlock_free(&dotlock);
-               return -1;
-       }
-
+       if ((ret = i_unlink_if_exists(lock_path)) == 0)
+               dotlock_replaced_warning(dotlock, TRUE);
        file_dotlock_free(&dotlock);
-       return 1;
+       return ret;
 }
 
 int file_dotlock_open(const struct dotlock_settings *set, const char *path,
index cffd4ea125fe86927fcc1e1affbf7c8de1e82ef1..8b696ef1a5aec02aae54dd132daa3ddbf2914a77 100644 (file)
@@ -242,7 +242,7 @@ int iostream_rawlog_create_prefix(const char *prefix, struct istream **input,
        if (out_fd == -1) {
                i_error("creat(%s) failed: %m", out_path);
                i_close_fd(&in_fd);
-               (void)unlink(in_path);
+               i_unlink(in_path);
                return -1;
        }
 
index 6aa69e3df48f53c19e49bf11cba86013a265b4f5..b3e6323d18f086004d08a47f312ab366469ad965 100644 (file)
@@ -58,8 +58,7 @@ static int o_stream_temp_move_to_fd(struct temp_ostream *tstream)
                i_error("safe_mkstemp(%s) failed: %m", str_c(path));
                return -1;
        }
-       if (unlink(str_c(path)) < 0) {
-               i_error("unlink(%s) failed: %m", str_c(path));
+       if (i_unlink(str_c(path)) < 0) {
                i_close_fd(&tstream->fd);
                return -1;
        }
index 1954341e656c151c30d69dad6db9bc330dd082d9..0125112fc75f559c8d594ea538bd04222d0ef7ca 100644 (file)
@@ -460,9 +460,8 @@ static int seekable_fd_callback(const char **path_r, void *context)
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("istream-seekable: unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index b2d75f5f865e48eaa904fa4219d102b2fc4058d5..b72a177657070b650851173c4913f29b8a0a3280 100644 (file)
@@ -542,8 +542,7 @@ int net_listen_unix_unlink_stale(const char *path, int backlog)
                }
 
                /* delete and try again */
-               if (unlink(path) < 0 && errno != ENOENT) {
-                       i_error("unlink(%s) failed: %m", path);
+               if (i_unlink_if_exists(path) < 0) {
                        errno = EADDRINUSE;
                        return -1;
                }
index 782d03a28a01d49fc24873e592b684caabe76c9c..c175bb556eb0a191abccab87d39166127fd88792 100644 (file)
@@ -64,7 +64,7 @@ safe_mkstemp_full(string_t *prefix, mode_t mode, uid_t uid, gid_t gid,
                                gid == (gid_t)-1 ? -1L : (long)gid);
                }
                i_close_fd(&fd);
-               (void)unlink(str_c(prefix));
+               i_unlink(str_c(prefix));
                return -1;
        }
        return fd;
index 3bad65825433de6e0630ed7e972894c95b0e3964..646d4affe9f77126fd96ec5a8dce809f650e181e 100644 (file)
@@ -17,7 +17,7 @@ static int fd_callback(const char **path_r, void *context ATTR_UNUSED)
        if (fd == -1)
                i_error("creat(%s) failed: %m", *path_r);
        else
-               unlink(*path_r);
+               i_unlink(*path_r);
        return fd;
 }
 
index a8bf27de01e62a2193d29fbebcd896832b99eb74..94998e37846b61e96888ba9e403355c1593b9c38 100644 (file)
@@ -24,8 +24,7 @@ static void test_ostream_file_random(void)
        fd = safe_mkstemp(path, 0600, (uid_t)-1, (gid_t)-1);
        if (fd == -1)
                i_fatal("safe_mkstemp(%s) failed: %m", str_c(path));
-       if (unlink(str_c(path)) < 0)
-               i_fatal("unlink(%s) failed: %m", str_c(path));
+       i_unlink(str_c(path));
        output = o_stream_create_fd(fd, MAX_BUFSIZE, FALSE);
        o_stream_cork(output);
 
index 2ccf3c7f8b072af1804c9d47075011c44cdca109..bd31b2b129b5cf2e809977281739660c197b2154 100644 (file)
@@ -54,8 +54,7 @@ unlink_old_files_real(const char *dir, const char *prefix, time_t min_time)
                        if (errno != ENOENT)
                                i_error("stat(%s) failed: %m", str_c(path));
                } else if (!S_ISDIR(st.st_mode) && st.st_ctime < min_time) {
-                       if (unlink(str_c(path)) < 0 && errno != ENOENT)
-                               i_error("unlink(%s) failed: %m", str_c(path));
+                       i_unlink_if_exists(str_c(path));
                }
        }
 
index bc6643629602e529997372d999bd0a0a2827deca..ea6bc4bf84a317ade457bdbc3e0ae8e387a229d0 100644 (file)
@@ -1168,9 +1168,8 @@ static int client_input_add_file(struct client *client,
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index 6dfc081f14e5a2d8184f206146a40b318aed14e5..d48571c2451099ff84de8cb95e4f1b21c4d1be50 100644 (file)
@@ -357,13 +357,13 @@ static void read_next_field(int fd, gnutls_datum *datum,
                i_fatal("read() failed for %s: %m", fname);
 
        if (ret != sizeof(datum->size)) {
-               (void)unlink(fname);
+               i_unlink(fname);
                i_fatal("Corrupted SSL parameter file %s: File too small",
                        fname);
        }
 
        if (datum->size > 10240) {
-               (void)unlink(fname);
+               i_unlink(fname);
                i_fatal("Corrupted SSL parameter file %s: "
                        "Field '%s' too large (%u)",
                        fname, field_name, datum->size);
@@ -376,7 +376,7 @@ static void read_next_field(int fd, gnutls_datum *datum,
                i_fatal("read() failed for %s: %m", fname);
 
        if ((size_t)ret != datum->size) {
-               (void)unlink(fname);
+               i_unlink(fname);
                i_fatal("Corrupted SSL parameter file %s: "
                        "Field '%s' not fully in file (%u < %u)",
                        fname, field_name, datum->size - ret, datum->size);
@@ -398,7 +398,7 @@ static void read_dh_parameters(int fd, const char *fname)
                read_next_field(fd, &dbits, fname, "DH bits");
 
                if (dbits.size != sizeof(int)) {
-                       (void)unlink(fname);
+                       i_unlink(fname);
                        i_fatal("Corrupted SSL parameter file %s: "
                                "Field 'DH bits' has invalid size %u",
                                fname, dbits.size);
index 265d056304a9eea2211469b3e0fa8ab045811a0d..ca9e277d4e56bbe1cc4ef151f0ba929cf18cec48 100644 (file)
@@ -217,8 +217,7 @@ static void fatal_log_check(const struct master_settings *set)
        }
 
        i_close_fd(&fd);
-       if (unlink(path) < 0)
-               i_error("unlink(%s) failed: %m", path);
+       i_unlink(path);
 }
 
 static bool pid_file_read(const char *path, pid_t *pid_r)
@@ -291,8 +290,7 @@ static void create_config_symlink(const struct master_settings *set)
        const char *base_config_path;
 
        base_config_path = t_strconcat(set->base_dir, "/"PACKAGE".conf", NULL);
-       if (unlink(base_config_path) < 0 && errno != ENOENT)
-               i_error("unlink(%s) failed: %m", base_config_path);
+       i_unlink_if_exists(base_config_path);
 
        if (symlink(services->config->config_file_path, base_config_path) < 0) {
                i_error("symlink(%s, %s) failed: %m",
@@ -553,8 +551,7 @@ static void main_deinit(void)
        global_dead_pipe_close();
        services_destroy(services, TRUE);
 
-       if (unlink(pidfile_path) < 0)
-               i_error("unlink(%s) failed: %m", pidfile_path);
+       i_unlink(pidfile_path);
        i_free(pidfile_path);
 
        service_anvil_global_deinit();
index ec33ba3c2ab7d8cc506d0ad9b9af2ad85ded559a..5e2c76322e6c3f3a315b5585fecb3be364e268e5 100644 (file)
@@ -711,8 +711,7 @@ static void unlink_sockets(const char *path, const char *prefix)
                        }
                }
 
-               if (unlink(str_c(str)) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", str_c(str));
+               i_unlink_if_exists(str_c(str));
        }
        (void)closedir(dirp);
 }
index 2e0f7dd243ab81553be624b478df14c3cfcc9a6a..f5112536e7e4c1379cfbd91f80d95d4f667d1cf1 100644 (file)
@@ -446,10 +446,7 @@ int services_listen_using(struct service_list *new_service_list,
                switch (old_listeners[j]->type) {
                case SERVICE_LISTENER_UNIX:
                case SERVICE_LISTENER_FIFO: {
-                       const char *path =
-                               old_listeners[j]->set.fileset.set->path;
-                       if (unlink(path) < 0)
-                               i_error("unlink(%s) failed: %m", path);
+                       i_unlink(old_listeners[j]->set.fileset.set->path);
                        break;
                }
                case SERVICE_LISTENER_INET:
index 22bc3897725099311da7148f2f69f6744e4b2f84..2d94960dc8bf3c33f9641bc2248acc2816ce748b 100644 (file)
@@ -137,8 +137,7 @@ static int acl_backend_vfile_acllist_read(struct acl_backend_vfile *backend)
 
                if (p == line || *p != ' ' || p[1] == '\0') {
                        i_error("Broken acllist file: %s", path);
-                       if (unlink(path) < 0 && errno != ENOENT)
-                               i_error("unlink(%s) failed: %m", path);
+                       i_unlink_if_exists(path);
                        i_close_fd(&fd);
                        return -1;
                }
@@ -316,8 +315,7 @@ acl_backend_vfile_acllist_try_rebuild(struct acl_backend_vfile *backend)
                (void)acl_lookup_dict_rebuild(auser->acl_lookup_dict);
        } else {
                acllist_clear(backend, 0);
-               if (unlink(str_c(path)) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", str_c(path));
+               i_unlink_if_exists(str_c(path));
        }
        backend->rebuilding_acllist = FALSE;
        return ret;
@@ -333,8 +331,7 @@ int acl_backend_vfile_acllist_rebuild(struct acl_backend_vfile *backend)
                /* delete it to make sure it gets rebuilt later */
                if (!acl_list_get_path(backend, &acllist_path))
                        i_unreached();
-               if (unlink(acllist_path) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", acllist_path);
+               i_unlink_if_exists(acllist_path);
                return -1;
        }
 }
index 48f3e4d96572173a26f606bf3cd04edd9fadc472..ed4157547fc8707b8a188ad5eebbee2521249ff5 100644 (file)
@@ -53,8 +53,8 @@ int main(int argc ATTR_UNUSED, char *argv[])
        double cputime;
 
        lib_init();
-       (void)unlink(trie_path);
-       (void)unlink(uidlist_path);
+       i_unlink_if_exists(trie_path);
+       i_unlink_if_exists(uidlist_path);
        trie = squat_trie_init(trie_path, time(NULL),
                               FILE_LOCK_METHOD_FCNTL, FALSE, 0600, (gid_t)-1);
 
index e7a65cb16c09852c7231061986217750f9b61335..083959e9b25c3a94e663ca6679ade8a4ed9535cd 100644 (file)
@@ -60,8 +60,7 @@ static int squat_trie_map(struct squat_trie *trie, bool building);
 
 void squat_trie_delete(struct squat_trie *trie)
 {
-       if (unlink(trie->path) < 0 && errno != ENOENT)
-               i_error("unlink(%s) failed: %m", trie->path);
+       i_unlink_if_exists(trie->path);
        squat_uidlist_delete(trie->uidlist);
 }
 
@@ -1704,8 +1703,7 @@ static int squat_trie_write(struct squat_trie_build_context *ctx)
        }
 
        if (ret < 0) {
-               if (unlink(path) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", path);
+               i_unlink_if_exists(path);
                if (file_lock != NULL)
                        file_lock_free(&file_lock);
        } else {
index fd19fdbda224600129dcfd60a0569e31b05c412d..890bbbeb4925b95da40bb1b7d204f7f84463be68 100644 (file)
@@ -92,8 +92,7 @@ static void squat_uidlist_close(struct squat_uidlist *uidlist);
 
 void squat_uidlist_delete(struct squat_uidlist *uidlist)
 {
-       if (unlink(uidlist->path) < 0 && errno != ENOENT)
-               i_error("unlink(%s) failed: %m", uidlist->path);
+       i_unlink_if_exists(uidlist->path);
 }
 
 static void squat_uidlist_set_corrupted(struct squat_uidlist *uidlist,
@@ -1084,10 +1083,8 @@ int squat_uidlist_rebuild_finish(struct squat_uidlist_rebuild_context *ctx,
        if (close(ctx->fd) < 0)
                i_error("close(%s) failed: %m", temp_path);
 
-       if (ret <= 0) {
-               if (unlink(temp_path) < 0)
-                       i_error("unlink(%s) failed: %m", temp_path);
-       }
+       if (ret <= 0)
+               i_unlink(temp_path);
        array_free(&ctx->new_block_offsets);
        array_free(&ctx->new_block_end_indexes);
        i_free(ctx);
index b7a80ee785f54685d8135ff968f426c6636afea4..c36bca13e74547b12fe739ec2d39f4dce4b03296 100644 (file)
@@ -442,9 +442,8 @@ fts_expunge_log_read_next(struct fts_expunge_log_read_ctx *ctx)
        (void)i_stream_read_data(ctx->input, &data, &size, IO_BLOCK_SIZE);
        if (size == 0 && ctx->input->stream_errno == 0) {
                /* expected EOF - mark the file as read by unlinking it */
-               if (ctx->unlink &&
-                   unlink(ctx->log->path) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", ctx->log->path);
+               if (ctx->unlink)
+                       i_unlink_if_exists(ctx->log->path);
 
                /* try reading again, in case something new was written */
                i_stream_sync(ctx->input);
@@ -510,9 +509,8 @@ int fts_expunge_log_read_end(struct fts_expunge_log_read_ctx **_ctx)
        *_ctx = NULL;
 
        if (ctx->corrupted) {
-               if (ctx->unlink &&
-                   unlink(ctx->log->path) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", ctx->log->path);
+               if (ctx->unlink)
+                       i_unlink_if_exists(ctx->log->path);
        }
 
        if (ctx->input != NULL)
index 804a81eee004d8ddd2a24794600fed56ba0ef907..516ed0fbd6f9dbf4154e0081d3178ba96b7e035f 100644 (file)
@@ -74,9 +74,8 @@ static int seekable_fd_callback(const char **path_r, void *context)
        }
 
        /* we just want the fd, unlink it */
-       if (unlink(str_c(path)) < 0) {
+       if (i_unlink(str_c(path)) < 0) {
                /* shouldn't happen.. */
-               i_error("unlink(%s) failed: %m", str_c(path));
                i_close_fd(&fd);
                return -1;
        }
index d0bad5013317abca2eb8a282642247694ba9876d..eca0ca62c906789ff1a9f234f94c2dac20f6776c 100644 (file)
@@ -304,16 +304,14 @@ static int maildirsize_write(struct maildir_quota_root *root, const char *path)
        if (write_full(fd, str_data(str), str_len(str)) < 0) {
                i_error("write_full(%s) failed: %m", str_c(temp_path));
                i_close_fd(&fd);
-               if (unlink(str_c(temp_path)) < 0)
-                       i_error("unlink(%s) failed: %m", str_c(temp_path));
+               i_unlink(str_c(temp_path));
                return -1;
        }
        i_close_fd(&fd);
 
        if (rename(str_c(temp_path), path) < 0) {
                i_error("rename(%s, %s) failed: %m", str_c(temp_path), path);
-               if (unlink(str_c(temp_path)) < 0 && errno != ENOENT)
-                       i_error("unlink(%s) failed: %m", str_c(temp_path));
+               i_unlink_if_exists(str_c(temp_path));
                return -1;
        }
        return 0;
index 9b47027fb41bda359ce42eb8649659293cf5dfa1..3f200ce5e5e2db19e34a33349ef46883c434ead6 100644 (file)
@@ -211,7 +211,7 @@ static int ssl_params_read(struct ssl_params *param)
        if (st.st_size == 0 || st.st_size > MAX_PARAM_FILE_SIZE) {
                i_error("Corrupted file: %s", param->path);
                i_close_fd(&fd);
-               (void)unlink(param->path);
+               i_unlink(param->path);
                return -1;
        }