diff options
| -rw-r--r-- | src/services/fs.rs | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/services/fs.rs b/src/services/fs.rs index aa07220..01df070 100644 --- a/src/services/fs.rs +++ b/src/services/fs.rs @@ -337,6 +337,19 @@ pub fn create_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<(), i32> { } } +pub fn create_dir_all<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<(), i32> { + let path = path.as_ref(); + let mut dir = PathBuf::new(); + let mut result = Ok(()); + + for component in path.components() { + let component = component.as_os_str(); + dir.push(component); + result = create_dir(arch, &dir); + } + result +} + pub fn metadata<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<Metadata, i32> { let maybe_file = File::open(&arch, path.as_ref()); let maybe_dir = read_dir(&arch, path.as_ref()); @@ -374,7 +387,18 @@ pub fn remove_dir_all<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<(), i32 } pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<ReadDir, i32> { - readdir(&arch, path.as_ref()) + unsafe { + let mut handle = 0; + let root = Arc::new(path.as_ref().to_path_buf()); + let path = to_utf16(path.as_ref()); + let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); + let r = FSUSER_OpenDirectory(&mut handle, arch.handle, fs_path); + if r < 0 { + Err(r) + } else { + Ok(ReadDir { handle: Dir(handle), root: root, arch: arch}) + } + } } pub fn remove_file<P: AsRef<Path>>(arch: &Archive, path: P) -> Result<(), i32> { @@ -413,21 +437,6 @@ pub fn rename<P, Q>(arch: &Archive, from: P, to: Q) -> Result<(), i32> } } -fn readdir<'a>(arch: &'a Archive, p: &Path) -> Result<ReadDir<'a>, i32> { - unsafe { - let mut handle = 0; - let root = Arc::new(p.to_path_buf()); - let path = to_utf16(p); - let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); - let r = FSUSER_OpenDirectory(&mut handle, arch.handle, fs_path); - if r < 0 { - Err(r) - } else { - Ok(ReadDir { handle: Dir(handle), root: root, arch: arch}) - } - } -} - // TODO: Determine if we should check UTF-16 paths for interior NULs fn to_utf16(path: &Path) -> Vec<u16> { path.as_os_str().encode_wide().collect::<Vec<_>>() |