From: Timo Sirainen Date: Tue, 4 Apr 2023 10:18:08 +0000 (+0300) Subject: config: Unlink temporary binary config file on failure X-Git-Tag: 2.4.0~2199 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1a847b84d93eb8858b26034d91eacdfd182b88f4;p=thirdparty%2Fdovecot%2Fcore.git config: Unlink temporary binary config file on failure --- diff --git a/src/config/config-dump-full.c b/src/config/config-dump-full.c index 56e1862320..c25bb1a85a 100644 --- a/src/config/config-dump-full.c +++ b/src/config/config-dump-full.c @@ -259,13 +259,19 @@ int config_dump_full(enum config_dump_full_dest dest, failed = TRUE; } - if (final_path != NULL && !failed) { + if (final_path == NULL) { + /* There is no temporary file. We're either writing to stdout + or the temporary file was already unlinked. */ + } else if (failed) { + i_unlink(str_c(path)); + } else { if (rename(str_c(path), final_path) < 0) { i_error("rename(%s, %s) failed: %m", str_c(path), final_path); /* the fd is still readable, so don't return failure */ } } + if (!failed && dest != CONFIG_DUMP_FULL_DEST_STDOUT && lseek(fd, 0, SEEK_SET) < 0) { i_error("lseek(%s, 0) failed: %m", o_stream_get_name(output));