on master help sign in
Detect non-existent files as non-readonly (#7875)
commitf01ca107fbf28c5dd65e238f775d708d738953b8 authorMichael Davis <mcarsondavis@gmail.com> dateTue 8 Aug 2023, 13:28 (3 years ago) parentcefc33e
1 file changed+6−1
helix-view/src/document.rs+6−1
helix-view/src/document.rs+6−1
@@ -965,7 +965,11 @@ impl Document {
965965 // Allows setting the flag for files the user cannot modify, like root files
966966 self.readonly = match &self.path {
967967 None => false,
968− Some(p) => access(p, Access::WRITE_OK).is_err(),
968+ Some(p) => match access(p, Access::WRITE_OK) {
969+ Ok(_) => false,
970+ Err(err) if err.kind() == std::io::ErrorKind::NotFound => false,
971+ Err(_) => true,
972+ },
969973 };
970974 }
971975
@@ -979,6 +983,7 @@ impl Document {
979983 self.readonly = match &self.path {
980984 None => false,
981985 Some(p) => match std::fs::metadata(p) {
986+ Err(err) if err.kind() == std::io::ErrorKind::NotFound => false,
982987 Err(_) => false,
983988 Ok(metadata) => metadata.permissions().readonly(),
984989 },