aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2016-06-21 19:49:12 +0900
committerJustin M. Keyes <justinkz@gmail.com>2016-08-04 19:01:52 -0400
commitb8c27a83b3d2c99e8a145d86410107f7220b6a75 (patch)
tree49e2b2b915642a873e37d07a2e3b0098e0849abd /src
parent0d93cd6c46e0b81e981197c4446aceb325325b5a (diff)
downloadrneovim-b8c27a83b3d2c99e8a145d86410107f7220b6a75.tar.gz
rneovim-b8c27a83b3d2c99e8a145d86410107f7220b6a75.tar.bz2
rneovim-b8c27a83b3d2c99e8a145d86410107f7220b6a75.zip
readfile(): Less-destructive readonly check.
Fixes #4162 Fixes #4200 Closes #4944 Regression by 4a138137f78907703aa9215b45f46b8f37d84ae5. That commit mentions a "possible race condition" but the cost isn't worth the (unexplained) gain.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/fileio.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 154558b332..cfce02cf27 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -493,22 +493,13 @@ 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 || !(os_getperm(fname) & 0222)) {
+ file_readonly = true;
}
+ fd = os_open((char *)fname, O_RDONLY, 0);
}
if (fd < 0) { /* cannot open at all */