]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Unlink temporary binary config file on failure
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 4 Apr 2023 10:18:08 +0000 (13:18 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 20 Nov 2023 12:20:55 +0000 (14:20 +0200)
src/config/config-dump-full.c

index 56e186232057c1790d06df7049e38cb75d537e59..c25bb1a85a3f624a345f1fe04e6987eb5aa2d2ef 100644 (file)
@@ -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));