Detect non-existent files as non-readonly (#7875)

pull/7878/head
Michael Davis 11 months ago committed by GitHub
parent cefc33e3df
commit f01ca107fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -965,7 +965,11 @@ impl Document {
// Allows setting the flag for files the user cannot modify, like root files // Allows setting the flag for files the user cannot modify, like root files
self.readonly = match &self.path { self.readonly = match &self.path {
None => false, 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 { self.readonly = match &self.path {
None => false, None => false,
Some(p) => match std::fs::metadata(p) { Some(p) => match std::fs::metadata(p) {
Err(err) if err.kind() == std::io::ErrorKind::NotFound => false,
Err(_) => false, Err(_) => false,
Ok(metadata) => metadata.permissions().readonly(), Ok(metadata) => metadata.permissions().readonly(),
}, },

Loading…
Cancel
Save