From a5f684737ff70f9823c0d8dad31543ec9f9b93b4 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 6 Nov 2022 12:11:06 +0100 Subject: [PATCH] Print OS error when ":write -force" fails to change permissions When the file system runs out of space, "write -force" will fail but doesn't print "No space left on device". Let's fix this by including such an underlying error. Untested. Backstory: I alias "w" to a command that runs "write -force %arg{@}". so I can overwrite files that already exist outside the editor (I should probably get used to the new behavior). --- src/file.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/file.cc b/src/file.cc index ee358be0..2c802f01 100644 --- a/src/file.cc +++ b/src/file.cc @@ -345,11 +345,11 @@ void write_buffer_to_file(Buffer& buffer, StringView filename, } if (force and ::chmod(zfilename, st.st_mode | S_IWUSR) < 0) - throw runtime_error("unable to change file permissions"); + throw runtime_error(format("unable to change file permissions: {}", strerror(errno))); auto restore_mode = on_scope_end([&]{ if ((force or replace) and ::chmod(zfilename, st.st_mode) < 0) - throw runtime_error("unable to restore file permissions"); + throw runtime_error(format("unable to restore file permissions: {}", strerror(errno))); }); char temp_filename[PATH_MAX];