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