From 3b607698740447743a77ce661cfae6a140c696a4 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 7 Sep 2022 13:05:28 +0900 Subject: [PATCH] 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. --- src/diff_edit.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/diff_edit.rs b/src/diff_edit.rs index 053648635..2b49166b3 100644 --- a/src/diff_edit.rs +++ b/src/diff_edit.rs @@ -82,14 +82,18 @@ fn check_out( } 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() { for entry in path.read_dir()? { set_readonly_recursively(&entry?.path())?; } + Ok(()) + } else { + let mut perms = std::fs::metadata(path)?.permissions(); + perms.set_readonly(true); + std::fs::set_permissions(path, perms) } - let mut perms = std::fs::metadata(path)?.permissions(); - perms.set_readonly(true); - std::fs::set_permissions(path, perms) } pub fn edit_diff(