Skip to content

Commit

Permalink
fs-posix: If link() fails, preserve its errno through the following u…
Browse files Browse the repository at this point in the history
…nlink()
  • Loading branch information
sirainen committed Apr 26, 2016
1 parent b7d31e7 commit e534a82
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib-fs/fs-posix.c
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit e534a82

Please sign in to comment.