Only compress regular file

This commit is contained in:
LoveSy 2023-12-09 01:11:58 +08:00 committed by topjohnwu
parent 8b7fae278b
commit 2ac464b186
2 changed files with 16 additions and 8 deletions

View File

@ -499,22 +499,30 @@ impl Cpio {
} }
impl CpioEntry { impl CpioEntry {
pub(crate) fn compress(&mut self) -> LoggedResult<()> { pub(crate) fn compress(&mut self) -> bool {
if self.mode & S_IFMT != S_IFREG {
return false;
}
let mut compressed = Vec::new(); let mut compressed = Vec::new();
if !xz(&self.data, &mut compressed) { if !xz(&self.data, &mut compressed) {
return Err(log_err!("xz compression failed")); eprintln!("xz compression failed");
return false;
} }
self.data = compressed; self.data = compressed;
Ok(()) true
} }
pub(crate) fn decompress(&mut self) -> LoggedResult<()> { pub(crate) fn decompress(&mut self) -> bool {
if self.mode & S_IFMT != S_IFREG {
return false;
}
let mut decompressed = Vec::new(); let mut decompressed = Vec::new();
if !unxz(&self.data, &mut decompressed) { if !unxz(&self.data, &mut decompressed) {
return Err(log_err!("xz decompression failed")); eprintln!("xz decompression failed");
return false;
} }
self.data = decompressed; self.data = decompressed;
Ok(()) true
} }
} }

View File

@ -95,7 +95,7 @@ impl MagiskCpio for Cpio {
rm_list.push_str(data); rm_list.push_str(data);
} }
} else if name != ".backup/.magisk" { } else if name != ".backup/.magisk" {
let new_name = if name.ends_with(".xz") && entry.decompress().is_ok() { let new_name = if name.ends_with(".xz") && entry.decompress() {
&name[8..name.len() - 3] &name[8..name.len() - 3]
} else { } else {
&name[8..] &name[8..]
@ -175,7 +175,7 @@ impl MagiskCpio for Cpio {
}; };
match action { match action {
Action::Backup(name, mut entry) => { Action::Backup(name, mut entry) => {
let backup = if !skip_compress && entry.compress().is_ok() { let backup = if !skip_compress && entry.compress() {
format!(".backup/{}.xz", name) format!(".backup/{}.xz", name)
} else { } else {
format!(".backup/{}", name) format!(".backup/{}", name)