From 607e6547a789cc368299b783274da5714e7f0494 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Mon, 12 Jun 2023 01:23:02 +0800 Subject: [PATCH] No check rm -r --- native/src/boot/cpio.rs | 22 ++++++---------------- native/src/boot/ramdisk.rs | 9 +++++---- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/native/src/boot/cpio.rs b/native/src/boot/cpio.rs index 1da77731b..18f0cea90 100644 --- a/native/src/boot/cpio.rs +++ b/native/src/boot/cpio.rs @@ -222,32 +222,22 @@ impl Cpio { Ok(()) } - pub(crate) fn rm(&mut self, path: &str, recursive: bool) -> anyhow::Result<()> { + pub(crate) fn rm(&mut self, path: &str, recursive: bool) { let path = norm_path(path); - let entry = self - .entries - .get(&path) - .ok_or(anyhow!("no such entry {}", path))?; - if entry.mode & S_IFMT == S_IFDIR && !recursive { - return Err(anyhow!("cannot remove directory without -r")); + if let Some(_) = self.entries.remove(&path) { + eprintln!("Removed entry [{}]", path); } - if entry.mode & S_IFMT != S_IFDIR && recursive { - return Err(anyhow!("cannot remove file with -r")); - } - self.entries.remove(&path); - eprintln!("Removed entry [{}]", path); if recursive { let path = path + "/"; self.entries.retain(|k, _| { if k.starts_with(&path) { eprintln!("Removed entry [{}]", k); - true - } else { false + } else { + true } }) } - Ok(()) } fn extract_entry(&self, path: &str, out: &Path) -> anyhow::Result<()> { @@ -481,7 +471,7 @@ pub fn cpio_commands(argc: i32, argv: *const *const c_char) -> bool { } } CpioCommands::Backup { origin } => cpio.backup(origin)?, - CpioCommands::Rm { path, recursive } => cpio.rm(path, *recursive)?, + CpioCommands::Rm { path, recursive } => cpio.rm(path, *recursive), CpioCommands::Mv { from, to } => cpio.mv(from, to)?, CpioCommands::Extract { path, out } => { cpio.extract(path.as_deref(), out.as_deref())? diff --git a/native/src/boot/ramdisk.rs b/native/src/boot/ramdisk.rs index 7428c5edb..a521ebc58 100644 --- a/native/src/boot/ramdisk.rs +++ b/native/src/boot/ramdisk.rs @@ -102,14 +102,14 @@ impl MagiskCpio for Cpio { backups.insert(name[8..].to_string(), entry); } }); - self.rm(".backup", false).ok(); + self.rm(".backup", false); if rm_list.is_empty() && backups.is_empty() { self.entries.clear(); return Ok(()); } for rm in rm_list.split('\0') { if !rm.is_empty() { - self.rm(rm, false)?; + self.rm(rm, false); } } self.entries.extend(backups); @@ -132,8 +132,8 @@ impl MagiskCpio for Cpio { }, ); let mut o = Cpio::load_from_file(origin)?; - o.rm(".backup", true).ok(); - self.rm(".backup", true).ok(); + o.rm(".backup", true); + self.rm(".backup", true); let mut lhs = o.entries.drain_filter(|_, _| true).peekable(); let mut rhs = self.entries.iter().peekable(); @@ -178,6 +178,7 @@ impl MagiskCpio for Cpio { backups.insert(backup, entry); } Action::Record(name) => { + eprintln!("Record new entry: [{}] -> [.backup/.rmlist]", name); rm_list.push_str(&format!("{}\0", name)); } Action::Noop => {}