diff_edit: do not make directories readonly

Otherwise directories containing files cannot be removed.

I think making files readonly is enough to tell user that the left side
cannot be edited, but I haven't tested that with Meld. If that's not enough,
we'll probably need to undo set_readonly_recursively() at exit.
This commit is contained in:
Yuya Nishihara 2022-09-07 13:05:28 +09:00
parent e4a39137c9
commit 3b60769874

View file

@ -82,14 +82,18 @@ fn check_out(
} }
fn set_readonly_recursively(path: &Path) -> Result<(), std::io::Error> { fn set_readonly_recursively(path: &Path) -> Result<(), std::io::Error> {
// Directory permission is unchanged since files under readonly directory cannot
// be removed.
if path.is_dir() { if path.is_dir() {
for entry in path.read_dir()? { for entry in path.read_dir()? {
set_readonly_recursively(&entry?.path())?; set_readonly_recursively(&entry?.path())?;
} }
} Ok(())
} else {
let mut perms = std::fs::metadata(path)?.permissions(); let mut perms = std::fs::metadata(path)?.permissions();
perms.set_readonly(true); perms.set_readonly(true);
std::fs::set_permissions(path, perms) std::fs::set_permissions(path, perms)
}
} }
pub fn edit_diff( pub fn edit_diff(