Merge #5159 from justinmk/readfile-readonly-check

This commit is contained in:
Justin M. Keyes 2016-08-04 19:18:59 -04:00 committed by GitHub
commit d622e9c416
1 changed files with 6 additions and 14 deletions

View File

@ -493,22 +493,14 @@ readfile (
curbuf->b_flags &= ~(BF_NEW | BF_NEW_W);
}
/*
* Check readonly by trying to open the file for writing.
* If this fails, we know that the file is readonly.
*/
file_readonly = FALSE;
// Check readonly.
file_readonly = false;
if (!read_buffer && !read_stdin) {
if (!newfile || readonlymode) {
file_readonly = TRUE;
} else if ((fd = os_open((char *)fname, O_RDWR, 0)) < 0) {
// opening in readwrite mode failed => file is readonly
file_readonly = TRUE;
}
if (file_readonly == TRUE) {
// try to open readonly
fd = os_open((char *)fname, O_RDONLY, 0);
if (!newfile || readonlymode || !(perm & 0222)
|| !os_file_is_writable((char *)fname)) {
file_readonly = true;
}
fd = os_open((char *)fname, O_RDONLY, 0);
}
if (fd < 0) { /* cannot open at all */