From b6e268500d62433b79f2471d3b1856b35cbdc8b1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 26 Mar 2014 19:11:04 +0000 Subject: [PATCH] notify buffer saved after closing the file descriptor --- src/file.cc | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/file.cc b/src/file.cc index 034bb5e2..01fc36c5 100644 --- a/src/file.cc +++ b/src/file.cc @@ -214,22 +214,24 @@ void write_buffer_to_file(Buffer& buffer, const String& filename) eolformat = "\n"; auto eoldata = eolformat.data(); - 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); }); - - if (buffer.options()["BOM"].get() == "utf-8") - ::write(fd, "\xEF\xBB\xBF", 3); - - for (LineCount i = 0; i < buffer.line_count(); ++i) { - // end of lines are written according to eolformat but always - // stored as \n - memoryview linedata = buffer[i].data(); - write(fd, linedata.subrange(0, linedata.size()-1), filename); - write(fd, eoldata, filename); + 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); }); + + if (buffer.options()["BOM"].get() == "utf-8") + ::write(fd, "\xEF\xBB\xBF", 3); + + for (LineCount i = 0; i < buffer.line_count(); ++i) + { + // end of lines are written according to eolformat but always + // stored as \n + memoryview linedata = buffer[i].data(); + write(fd, linedata.subrange(0, linedata.size()-1), filename); + write(fd, eoldata, filename); + } } if ((buffer.flags() & Buffer::Flags::File) and filename == buffer.name()) buffer.notify_saved();