diff options
author | Michael Davis | 2023-08-08 18:28:53 +0000 |
---|---|---|
committer | GitHub | 2023-08-08 18:28:53 +0000 |
commit | f01ca107fbf28c5dd65e238f775d708d738953b8 (patch) | |
tree | 5e644c16b7386fbfcbaab28ca8e3ca6060d0f252 | |
parent | cefc33e3dfffd5136bcc9b77aea481e3b0de6ae9 (diff) |
Detect non-existent files as non-readonly (#7875)
-rw-r--r-- | helix-view/src/document.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 7602c9c7..3477608b 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -965,7 +965,11 @@ impl Document { // Allows setting the flag for files the user cannot modify, like root files self.readonly = match &self.path { None => false, - Some(p) => access(p, Access::WRITE_OK).is_err(), + Some(p) => match access(p, Access::WRITE_OK) { + Ok(_) => false, + Err(err) if err.kind() == std::io::ErrorKind::NotFound => false, + Err(_) => true, + }, }; } @@ -979,6 +983,7 @@ impl Document { self.readonly = match &self.path { None => false, Some(p) => match std::fs::metadata(p) { + Err(err) if err.kind() == std::io::ErrorKind::NotFound => false, Err(_) => false, Ok(metadata) => metadata.permissions().readonly(), }, |