Merge remote-tracking branch 'krobelus/perror-on-chmod-failure'

This commit is contained in:
Maxime Coste 2023-03-13 21:34:13 +11:00
commit c8f682f3ad

View File

@ -345,11 +345,11 @@ void write_buffer_to_file(Buffer& buffer, StringView filename,
} }
if (force and ::chmod(zfilename, st.st_mode | S_IWUSR) < 0) 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([&]{ auto restore_mode = on_scope_end([&]{
if ((force or replace) and ::chmod(zfilename, st.st_mode) < 0) 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]; char temp_filename[PATH_MAX];