From c7356c8e9c28de0f76895a0436246a462b3f98e2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 3 Oct 2016 20:00:36 +0100 Subject: [PATCH] Close write buffer file descriptor before getting the new fs timestamp --- src/file.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/file.cc b/src/file.cc index 9940d7f8..a4ea99b0 100644 --- a/src/file.cc +++ b/src/file.cc @@ -260,9 +260,11 @@ void write_buffer_to_file(Buffer& buffer, StringView filename) O_CREAT | O_WRONLY | O_TRUNC, 0644); if (fd == -1) throw file_access_error(filename, strerror(errno)); - auto close_fd = on_scope_end([fd]{ close(fd); }); - write_buffer_to_fd(buffer, fd); + { + auto close_fd = on_scope_end([fd]{ close(fd); }); + write_buffer_to_fd(buffer, fd); + } if ((buffer.flags() & Buffer::Flags::File) and real_path(filename) == real_path(buffer.name()))