From 2ac464b18652e716574fe04e1250bdc35d759679 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sat, 9 Dec 2023 01:11:58 +0800 Subject: [PATCH] Only compress regular file --- native/src/boot/cpio.rs | 20 ++++++++++++++------ native/src/boot/ramdisk.rs | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/native/src/boot/cpio.rs b/native/src/boot/cpio.rs index cfb8db411..30509c95a 100644 --- a/native/src/boot/cpio.rs +++ b/native/src/boot/cpio.rs @@ -499,22 +499,30 @@ impl Cpio { } 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(); if !xz(&self.data, &mut compressed) { - return Err(log_err!("xz compression failed")); + eprintln!("xz compression failed"); + return false; } 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(); if !unxz(&self.data, &mut decompressed) { - return Err(log_err!("xz decompression failed")); + eprintln!("xz decompression failed"); + return false; } self.data = decompressed; - Ok(()) + true } } diff --git a/native/src/boot/ramdisk.rs b/native/src/boot/ramdisk.rs index 1014860a5..5662e3c6f 100644 --- a/native/src/boot/ramdisk.rs +++ b/native/src/boot/ramdisk.rs @@ -95,7 +95,7 @@ impl MagiskCpio for Cpio { rm_list.push_str(data); } } 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] } else { &name[8..] @@ -175,7 +175,7 @@ impl MagiskCpio for Cpio { }; match action { 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) } else { format!(".backup/{}", name)