mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-29 14:04:26 +02:00
Better path methods
This commit is contained in:
parent
0c70b7670c
commit
4ad26d3dfb
@ -415,17 +415,19 @@ impl Utf8CStr {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn parent(&self, buf: &mut dyn Utf8CStrBuf) -> bool {
|
||||
buf.clear();
|
||||
if let Some(parent) = Path::new(self.as_str()).parent() {
|
||||
let bytes = parent.as_os_str().as_bytes();
|
||||
pub fn parent_dir(&self) -> Option<&str> {
|
||||
Path::new(self.as_str())
|
||||
.parent()
|
||||
.map(Path::as_os_str)
|
||||
// SAFETY: all substring of self is valid UTF-8
|
||||
let parent = unsafe { std::str::from_utf8_unchecked(bytes) };
|
||||
buf.push_str(parent);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
.map(|s| unsafe { std::str::from_utf8_unchecked(s.as_bytes()) })
|
||||
}
|
||||
|
||||
pub fn file_name(&self) -> Option<&str> {
|
||||
Path::new(self.as_str())
|
||||
.file_name()
|
||||
// SAFETY: all substring of self is valid UTF-8
|
||||
.map(|s| unsafe { std::str::from_utf8_unchecked(s.as_bytes()) })
|
||||
}
|
||||
|
||||
// ln self path
|
||||
|
@ -346,7 +346,8 @@ impl Cpio {
|
||||
let mut buf = cstr::buf::default();
|
||||
|
||||
// Make sure its parent directories exist
|
||||
if out.parent(&mut buf) {
|
||||
if let Some(dir) = out.parent_dir() {
|
||||
buf.push_str(dir);
|
||||
buf.mkdirs(0o755)?;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user