mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
Remove for_all_file
This commit is contained in:
parent
4745e86c1b
commit
6a59939d9a
@ -295,27 +295,6 @@ impl Directory {
|
|||||||
})?;
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn for_all_file<F: FnMut(&DirEntry) -> io::Result<WalkResult>>(
|
|
||||||
&mut self,
|
|
||||||
mut f: F,
|
|
||||||
) -> io::Result<WalkResult> {
|
|
||||||
use WalkResult::*;
|
|
||||||
loop {
|
|
||||||
match self.read()? {
|
|
||||||
None => return Ok(Continue),
|
|
||||||
Some(ref e) => {
|
|
||||||
if e.is_dir() {
|
|
||||||
return Ok(Continue);
|
|
||||||
}
|
|
||||||
match f(e)? {
|
|
||||||
Abort | Skip => return Ok(Continue),
|
|
||||||
Continue => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Directory {
|
impl Directory {
|
||||||
|
@ -86,7 +86,7 @@ fn file_get_prop(name: &Utf8CStr) -> LoggedResult<String> {
|
|||||||
.join(PERSIST_PROP_DIR!())
|
.join(PERSIST_PROP_DIR!())
|
||||||
.join(name);
|
.join(name);
|
||||||
let mut file = path.open(O_RDONLY | O_CLOEXEC)?;
|
let mut file = path.open(O_RDONLY | O_CLOEXEC)?;
|
||||||
debug!("resetprop: read prop from [{}]\n", path);
|
debug!("resetprop: read prop from [{}]", path);
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
file.read_to_string(&mut s)?;
|
file.read_to_string(&mut s)?;
|
||||||
Ok(s)
|
Ok(s)
|
||||||
@ -99,7 +99,9 @@ fn file_set_prop(name: &Utf8CStr, value: Option<&Utf8CStr>) -> LoggedResult<()>
|
|||||||
.join(name);
|
.join(name);
|
||||||
if let Some(value) = value {
|
if let Some(value) = value {
|
||||||
let mut buf = Utf8CStrArr::default();
|
let mut buf = Utf8CStrArr::default();
|
||||||
let mut tmp = FsPathBuf::new(&mut buf).join(concat!(PERSIST_PROP_DIR!(), ".prop.XXXXXX"));
|
let mut tmp = FsPathBuf::new(&mut buf)
|
||||||
|
.join(PERSIST_PROP_DIR!())
|
||||||
|
.join("prop.XXXXXX");
|
||||||
{
|
{
|
||||||
let mut f = unsafe {
|
let mut f = unsafe {
|
||||||
let fd = mkstemp(tmp.as_mut_ptr()).check_os_err()?;
|
let fd = mkstemp(tmp.as_mut_ptr()).check_os_err()?;
|
||||||
@ -107,10 +109,10 @@ fn file_set_prop(name: &Utf8CStr, value: Option<&Utf8CStr>) -> LoggedResult<()>
|
|||||||
};
|
};
|
||||||
f.write_all(value.as_bytes())?;
|
f.write_all(value.as_bytes())?;
|
||||||
}
|
}
|
||||||
debug!("resetprop: write prop to [{}]\n", tmp);
|
debug!("resetprop: write prop to [{}]", tmp);
|
||||||
tmp.rename_to(path)?
|
tmp.rename_to(path)?
|
||||||
} else {
|
} else {
|
||||||
debug!("resetprop: unlink [{}]\n", path);
|
debug!("resetprop: unlink [{}]", path);
|
||||||
path.remove()?;
|
path.remove()?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -180,13 +182,16 @@ pub unsafe fn persist_get_props(prop_cb: Pin<&mut PropCb>) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let mut dir = Directory::open(cstr!(PERSIST_PROP_DIR!()))?;
|
let mut dir = Directory::open(cstr!(PERSIST_PROP_DIR!()))?;
|
||||||
dir.for_all_file(|f| {
|
dir.pre_order_walk(|e| {
|
||||||
if let Ok(name) = Utf8CStr::from_bytes(f.d_name().to_bytes()) {
|
if e.is_file() {
|
||||||
if let Ok(mut value) = file_get_prop(name) {
|
if let Ok(name) = Utf8CStr::from_cstr(e.d_name()) {
|
||||||
prop_cb.exec(name, Utf8CStr::from_string(&mut value));
|
if let Ok(mut value) = file_get_prop(name) {
|
||||||
|
prop_cb.exec(name, Utf8CStr::from_string(&mut value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(WalkResult::Continue)
|
// Do not traverse recursively
|
||||||
|
Ok(WalkResult::Skip)
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user