mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-21 23:47:39 +00:00
No check rm -r
This commit is contained in:
parent
6b21091fe2
commit
607e6547a7
@ -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())?
|
||||
|
@ -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 => {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user