diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-08-04 19:18:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-04 19:18:59 -0400 |
commit | d622e9c41635d9c0a65b8725e49ce476838d1aa2 (patch) | |
tree | ac4dfe1952abbe9d9d43602d69a9cb3a8a0a96e9 /src | |
parent | 5a8ae8d3fe983e53ec2806e4fefc48d55e3415b9 (diff) | |
parent | a8d1b5f721f51c1efbe6f55f3515f159ad0dfc8c (diff) | |
download | rneovim-d622e9c41635d9c0a65b8725e49ce476838d1aa2.tar.gz rneovim-d622e9c41635d9c0a65b8725e49ce476838d1aa2.tar.bz2 rneovim-d622e9c41635d9c0a65b8725e49ce476838d1aa2.zip |
Merge #5159 from justinmk/readfile-readonly-check
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/fileio.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 154558b332..3b598bd64b 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -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 */ |