Skip to content

Commit

Permalink
Detect non-existent files as non-readonly (helix-editor#7875)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis authored and Schuyler Mortimer committed Jul 10, 2024
1 parent 5566fd0 commit f03fe7f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
}

Expand All @@ -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(),
},
Expand Down

0 comments on commit f03fe7f

Please sign in to comment.