mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
Detect non-existent files as non-readonly (#7875)
This commit is contained in:
parent
cefc33e3df
commit
f01ca107fb
@ -965,7 +965,11 @@ pub fn detect_readonly(&mut self) {
|
||||
// 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 @@ pub fn detect_readonly(&mut self) {
|
||||
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(),
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user