Close fd before notifiying buffer of modification when writing to file

This commit is contained in:
Maxime Coste 2014-10-22 19:23:54 +01:00
parent b2e90fe21e
commit 7f23d4b756

View File

@ -194,6 +194,7 @@ void write_buffer_to_file(Buffer& buffer, StringView filename)
{ {
buffer.run_hook_in_own_context("BufWritePre", buffer.name()); buffer.run_hook_in_own_context("BufWritePre", buffer.name());
{
int fd = open(parse_filename(filename).c_str(), int fd = open(parse_filename(filename).c_str(),
O_CREAT | O_WRONLY | O_TRUNC, 0644); O_CREAT | O_WRONLY | O_TRUNC, 0644);
if (fd == -1) if (fd == -1)
@ -201,6 +202,7 @@ void write_buffer_to_file(Buffer& buffer, StringView filename)
auto close_fd = on_scope_end([fd]{ close(fd); }); 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 if ((buffer.flags() & Buffer::Flags::File) and
real_path(filename) == real_path(buffer.name())) real_path(filename) == real_path(buffer.name()))