summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-10-22 19:23:54 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-10-22 19:23:54 +0100
commit7f23d4b756fc419787408b3be7c7fcc9dfe01cc9 (patch)
treed56723e8c102d3ef2bedd1b87b39329f13753339 /src
parentb2e90fe21eb2bffd65d66fb40c02195cabbb3fa3 (diff)
Close fd before notifiying buffer of modification when writing to file
Diffstat (limited to 'src')
-rw-r--r--src/file.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/file.cc b/src/file.cc
index 3f6b71aa..a8c20205 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -194,13 +194,15 @@ void write_buffer_to_file(Buffer& buffer, StringView filename)
{
buffer.run_hook_in_own_context("BufWritePre", buffer.name());
- int fd = open(parse_filename(filename).c_str(),
- 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); });
+ {
+ int fd = open(parse_filename(filename).c_str(),
+ 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);
+ write_buffer_to_fd(buffer, fd);
+ }
if ((buffer.flags() & Buffer::Flags::File) and
real_path(filename) == real_path(buffer.name()))