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;
}
!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;
}
}
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;
}
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;
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);
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);
}
}
/* 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;
}
}
/* 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;
}
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();
}
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 &&
}
/* 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;
}
}
/* 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;
}
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)
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)
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);
}
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;
}
ret = -1;
}
if (ret < 0)
- (void)unlink(temp_path);
+ i_unlink(temp_path);
return ret;
}
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;
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);
(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;
i_free(log->head);
i_free(log->index);
i_free(log);
- unlink(tmp_path);
+ i_unlink(tmp_path);
}
int main(void)
}
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)
}
/* 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;
}
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;
}
} else {
return 0;
}
- (void)unlink(str_c(temp_path));
+ i_unlink(str_c(temp_path));
return -1;
}
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) {
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) {
/* 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;
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,
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;
}
}
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. */
}
/* 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;
}
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++) {
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;
}
if (ret == 0) {
/* file is broken */
- (void)unlink(uidlist->path);
+ i_unlink(uidlist->path);
} else if (ret > 0) {
/* success */
if (readonly)
}
/* 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;
}
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;
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;
}
}
}
if (ret < 0)
- (void)unlink(tmppath);
+ i_unlink(tmppath);
} T_END;
return ret;
}
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;
}
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
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;
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;
struct dotlock *dotlock;
const char *lock_path;
struct stat st;
+ int ret;
dotlock = *dotlock_p;
*dotlock_p = NULL;
(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,
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;
}
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;
}
}
/* 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;
}
}
/* 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;
}
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;
if (fd == -1)
i_error("creat(%s) failed: %m", *path_r);
else
- unlink(*path_r);
+ i_unlink(*path_r);
return fd;
}
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);
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));
}
}
}
/* 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;
}
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);
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);
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);
}
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)
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",
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();
}
}
- 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);
}
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:
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;
}
(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;
/* 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;
}
}
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);
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);
}
}
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 {
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,
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);
(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);
*_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)
}
/* 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;
}
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;
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;
}