]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fs-posix: If link() fails, preserve its errno through the following unlink()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 11 Apr 2016 14:25:51 +0000 (17:25 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 26 Apr 2016 08:27:45 +0000 (11:27 +0300)
src/lib-fs/fs-posix.c

index 6f3e99c1c27f1d83a0190f63c22c2e43668b4a6d..ddd9ccb6871195f0771a98a912380b7f4f27f986 100644 (file)
@@ -431,7 +431,7 @@ fs_posix_read_stream(struct fs_file *_file, size_t max_buffer_size)
 
 static int fs_posix_write_finish(struct posix_fs_file *file)
 {
-       int ret;
+       int ret, old_errno;
 
        if ((file->open_flags & FS_OPEN_FLAG_FSYNC) != 0) {
                if (fdatasync(file->fd) < 0) {
@@ -448,10 +448,12 @@ static int fs_posix_write_finish(struct posix_fs_file *file)
                        fs_set_error(file->file.fs, "link(%s, %s) failed: %m",
                                     file->temp_path, file->full_path);
                }
+               old_errno = errno;
                if (unlink(file->temp_path) < 0) {
                        fs_set_error(file->file.fs, "unlink(%s) failed: %m",
                                     file->temp_path);
                }
+               errno = old_errno;
                if (ret < 0) {
                        fs_posix_file_close(&file->file);
                        i_free_and_null(file->temp_path);