From: Timo Sirainen Date: Mon, 11 Apr 2016 14:25:51 +0000 (+0300) Subject: fs-posix: If link() fails, preserve its errno through the following unlink() X-Git-Tag: 2.2.24~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e534a82dc63ad78d9a0aec777193c6a1433289a8;p=thirdparty%2Fdovecot%2Fcore.git fs-posix: If link() fails, preserve its errno through the following unlink() --- diff --git a/src/lib-fs/fs-posix.c b/src/lib-fs/fs-posix.c index 6f3e99c1c2..ddd9ccb687 100644 --- a/src/lib-fs/fs-posix.c +++ b/src/lib-fs/fs-posix.c @@ -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);