@@ -4,7 +4,6 @@ use std::path::Path;
44use std:: path:: PathBuf ;
55use std:: process:: Command ;
66use std:: process:: Stdio ;
7- use std:: io:: Result ;
87
98use anyhow:: Context ;
109use anyhow:: Result ;
@@ -154,21 +153,12 @@ fn parse_kmi_from_boot(magiskboot: &Path, image: &PathBuf, workdir: &Path) -> Re
154153 parse_kmi_from_kernel ( & image_path, workdir)
155154}
156155
157- fn do_cpio_cmd ( magiskboot : & Path , workdir : & Path , cmd : & str ) -> Result < ( ) > {
158- let status = Command :: new ( magiskboot)
159- . current_dir ( workdir)
160- . stdout ( Stdio :: null ( ) )
161- . stderr ( Stdio :: null ( ) )
162- . arg ( "cpio" )
163- . arg ( "ramdisk.cpio" )
164- . arg ( cmd)
165- . status ( ) ?;
166-
167- ensure ! ( status. success( ) , "magiskboot cpio {} failed" , cmd) ;
168- Ok ( ( ) )
169- }
170-
171- fn do_cpio_cmd ( magiskboot : impl AsRef < Path > , workdir : impl AsRef < Path > , cpio_path : impl AsRef < Path > , cmd : & str ) -> Result < ( ) > {
156+ fn do_cpio_cmd (
157+ magiskboot : impl AsRef < Path > ,
158+ workdir : impl AsRef < Path > ,
159+ cpio_path : impl AsRef < Path > ,
160+ cmd : & str ,
161+ ) -> Result < ( ) > {
172162 let status = Command :: new ( magiskboot)
173163 . current_dir ( workdir)
174164 . stdout ( Stdio :: null ( ) )
@@ -181,19 +171,11 @@ fn do_cpio_cmd(magiskboot: impl AsRef<Path>, workdir: impl AsRef<Path>, cpio_pat
181171 Ok ( ( ) )
182172}
183173
184- fn is_magisk_patched ( magiskboot : & Path , workdir : & Path ) -> Result < bool > {
185- let status = Command :: new ( magiskboot)
186- . current_dir ( workdir)
187- . stdout ( Stdio :: null ( ) )
188- . stderr ( Stdio :: null ( ) )
189- . args ( [ "cpio" , "ramdisk.cpio" , "test" ] )
190- . status ( ) ?;
191-
192- // 0: stock, 1: magisk
193- Ok ( status. code ( ) == Some ( 1 ) )
194- }
195-
196- fn is_magisk_patched ( magiskboot : impl AsRef < Path > , workdir : impl AsRef < Path > , cpio_path : impl AsRef < Path > ) {
174+ fn is_magisk_patched (
175+ magiskboot : impl AsRef < Path > ,
176+ workdir : impl AsRef < Path > ,
177+ cpio_path : impl AsRef < Path > ,
178+ ) {
197179 let status = Command :: new ( magiskboot)
198180 . current_dir ( workdir)
199181 . stdout ( Stdio :: null ( ) )
@@ -207,7 +189,7 @@ fn is_magisk_patched(magiskboot: impl AsRef<Path>, workdir: impl AsRef<Path>, cp
207189}
208190
209191fn is_kernelsu_patched ( magiskboot : & Path , workdir : & Path , target : & str ) -> Result < bool > {
210- let cpio_path: PathBuf = match target {
192+ let cpio_path = match target {
211193 "ramdisk.cpio" => PathBuf :: from ( "ramdisk.cpio" ) ,
212194 "vendor/init_boot.cpio" => workdir. join ( "vendor_ramdisk" ) . join ( "init_boot.cpio" ) ,
213195 "vendor/ramdisk.cpio" => workdir. join ( "vendor_ramdisk" ) . join ( "ramdisk.cpio" ) ,
@@ -218,11 +200,7 @@ fn is_kernelsu_patched(magiskboot: &Path, workdir: &Path, target: &str) -> Resul
218200 . current_dir ( workdir)
219201 . stdout ( Stdio :: null ( ) )
220202 . stderr ( Stdio :: null ( ) )
221- . args ( [
222- "cpio" ,
223- cpio_path. to_str ( ) . unwrap ( ) ,
224- "exists kernelsu.ko" ,
225- ] )
203+ . args ( [ "cpio" , cpio_path. to_str ( ) . unwrap ( ) , "exists kernelsu.ko" ] )
226204 . status ( ) ?;
227205
228206 Ok ( status. success ( ) )
@@ -319,24 +297,22 @@ pub fn restore(
319297 if no_ramdisk {
320298 if !no_vendor_init_boot {
321299 // vendor init_boot restore
322- do_vendor_init_boot_cpio_cmd ( & magiskboot, workdir, "rm kernelsu.ko" ) ?;
300+ do_cpio_cmd ( & magiskboot, workdir, "rm kernelsu.ko" ) ?;
323301
324- let status =
325- do_vendor_init_boot_cpio_cmd ( & magiskboot, workdir, "exists init.real" ) . is_ok ( ) ;
302+ let status = do_cpio_cmd ( & magiskboot, workdir, "exists init.real" ) . is_ok ( ) ;
326303 if status {
327- do_vendor_init_boot_cpio_cmd ( & magiskboot, workdir, "mv init.real init" ) ?;
304+ do_cpio_cmd ( & magiskboot, workdir, "mv init.real init" ) ?;
328305 } else {
329306 let vendor_init_boot = workdir. join ( "vendor_ramdisk" ) . join ( "init_boot.cpio" ) ;
330307 std:: fs:: remove_file ( vendor_init_boot) ?;
331308 }
332309 } else if !no_vendor_ramdisk {
333310 // vendor ramdisk restore
334- do_vendor_ramdisk_cpio_cmd ( & magiskboot, workdir, "rm kernelsu.ko" ) ?;
311+ do_cpio_cmd ( & magiskboot, workdir, "rm kernelsu.ko" ) ?;
335312
336- let status =
337- do_vendor_ramdisk_cpio_cmd ( & magiskboot, workdir, "exists init.real" ) . is_ok ( ) ;
313+ let status = do_cpio_cmd ( & magiskboot, workdir, "exists init.real" ) . is_ok ( ) ;
338314 if status {
339- do_vendor_ramdisk_cpio_cmd ( & magiskboot, workdir, "mv init.real init" ) ?;
315+ do_cpio_cmd ( & magiskboot, workdir, "mv init.real init" ) ?;
340316 } else {
341317 let vendor_ramdisk = workdir. join ( "vendor_ramdisk" ) . join ( "ramdisk.cpio" ) ;
342318 std:: fs:: remove_file ( vendor_ramdisk) ?;
@@ -561,7 +537,12 @@ fn do_patch(
561537 }
562538
563539 do_cpio_cmd ( & magiskboot, workdir, ramdisk, "add 0755 init init" ) ?;
564- do_cpio_cmd ( & magiskboot, workdir, ramdisk, "add 0755 kernelsu.ko kernelsu.ko" ) ?;
540+ do_cpio_cmd (
541+ & magiskboot,
542+ workdir,
543+ ramdisk,
544+ "add 0755 kernelsu.ko kernelsu.ko" ,
545+ ) ?;
565546
566547 #[ cfg( target_os = "android" ) ]
567548 if need_backup {
0 commit comments