@@ -66,7 +66,7 @@ impl MagiskInit {
6666 }
6767 }
6868
69- pub ( crate ) fn load_overlay_rc ( & mut self , overlay : & Utf8CStr ) {
69+ pub ( crate ) fn load_overlay_rc ( & mut self , overlay : & Utf8CStr , module_path : & Utf8CStr ) {
7070 if let Ok ( mut dir) = Directory :: open ( overlay) {
7171 let init_rc = cstr:: buf:: dynamic ( 256 )
7272 . join_path ( overlay)
@@ -78,24 +78,40 @@ impl MagiskInit {
7878 loop {
7979 match dir. read ( ) {
8080 Ok ( None ) => break ,
81- Ok ( Some ( e) ) if e. is_file ( ) && e. name ( ) . ends_with ( ".rc" ) => {
82- let name = e. name ( ) ;
83- let mut path = cstr:: buf:: dynamic ( 256 ) . join_path ( "/" ) . join_path ( name) ;
84- if path. exists ( ) {
85- debug ! ( "Replace rc script [{}]" , name) ;
86- } else {
87- debug ! ( "Found rc script [{}]" , name) ;
88- path = cstr:: buf:: dynamic ( 256 ) . join_path ( overlay) . join_path ( name) ;
89- let mut rc_content = String :: new ( ) ;
90- if let Ok ( mut file) = path. open ( O_RDONLY | O_CLOEXEC ) {
91- file. read_to_string ( & mut rc_content) . log_ok ( ) ;
92- self . rc_list . push ( rc_content) ;
93- drop ( file) ;
94- path. remove ( ) . log_ok ( ) ;
81+ Ok ( Some ( e) ) => {
82+ let recursive = cstr:: buf:: dynamic ( 256 ) . join_path ( module_path) . exists ( ) ;
83+ if ( recursive && e. is_dir ( ) ) || e. is_file ( ) {
84+ let buf = & mut cstr:: buf:: dynamic ( 256 ) ;
85+ e. resolve_path ( buf) . log_ok ( ) ;
86+ if e. is_file ( ) && buf. ends_with ( ".rc" ) {
87+ let mut path;
88+ if recursive {
89+ path = cstr:: buf:: dynamic ( 256 )
90+ . join_path ( buf. replace ( module_path. as_str ( ) , "" ) ) ;
91+ } else {
92+ path =
93+ cstr:: buf:: dynamic ( 256 ) . join_path ( "/" ) . join_path ( e. name ( ) ) ;
94+ }
95+ if path. exists ( ) {
96+ debug ! ( "Replace rc script [{}] -> [{}]" , path, buf) ;
97+ } else {
98+ path = cstr:: buf:: dynamic ( 256 ) . join_path ( buf) ;
99+ debug ! ( "Found rc script [{}]" , path) ;
100+ let mut rc_content = String :: new ( ) ;
101+ if let Ok ( mut file) = path. open ( O_RDONLY | O_CLOEXEC ) {
102+ file. read_to_string ( & mut rc_content) . log_ok ( ) ;
103+ self . rc_list . push ( rc_content) ;
104+ drop ( file) ;
105+ path. remove ( ) . log_ok ( ) ;
106+ }
107+ }
108+ } else if e. is_dir ( ) {
109+ self . load_overlay_rc ( buf, module_path) ;
95110 }
111+ } else {
112+ continue ;
96113 }
97114 }
98- Ok ( _) => continue ,
99115 Err ( _) => break ,
100116 }
101117 }
@@ -108,12 +124,10 @@ impl MagiskInit {
108124 match dir. read ( ) {
109125 Ok ( None ) => break ,
110126 Ok ( Some ( e) ) if e. is_dir ( ) => {
111- let name = e. name ( ) ;
112- let path = cstr:: buf:: dynamic ( 256 )
113- . join_path ( "/data" )
114- . join_path ( PREINITMIRR )
115- . join_path ( name) ;
116- self . load_overlay_rc ( & path) ;
127+ let buf = & mut cstr:: buf:: dynamic ( 256 ) ;
128+ e. resolve_path ( buf) . log_ok ( ) ;
129+ let path = cstr:: buf:: dynamic ( 256 ) . join_path ( & mut * buf) ;
130+ self . load_overlay_rc ( & path, buf) ;
117131 let desc_path = cstr:: buf:: dynamic ( 256 ) . join_path ( root_dir) ;
118132 path. copy_to ( & desc_path) . log_ok ( ) ;
119133 }
0 commit comments