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>(arch: &Archive, path: P) -> Result<(), i32> { } } +pub fn create_dir_all>(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>(arch: &Archive, path: P) -> Result { 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>(arch: &Archive, path: P) -> Result<(), i32 } pub fn read_dir>(arch: &Archive, path: P) -> Result { - 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>(arch: &Archive, path: P) -> Result<(), i32> { @@ -413,21 +437,6 @@ pub fn rename(arch: &Archive, from: P, to: Q) -> Result<(), i32> } } -fn readdir<'a>(arch: &'a Archive, p: &Path) -> Result, 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 { path.as_os_str().encode_wide().collect::>()