diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 67d3118..f2f1d2f 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -3,7 +3,6 @@ use std::{ env, fs, io::{self, prelude::*}, - path::Component, path::{Path, PathBuf}, }; @@ -12,7 +11,7 @@ use zip::{self, read::ZipFile, ZipArchive}; use crate::{ info, oof, - utils::{self, dir_is_empty, Bytes}, + utils::{self, dir_is_empty, strip_cur_dir, Bytes}, }; use self::utf8::get_invalid_utf8_paths; @@ -48,7 +47,7 @@ where fs::create_dir_all(&path)?; } } - let file_path = file_path.strip_prefix(Component::CurDir).unwrap_or_else(|_| file_path.as_path()); + let file_path = strip_cur_dir(file_path.as_path()); info!("{:?} extracted. ({})", file_path.display(), Bytes::new(file.size())); diff --git a/src/utils.rs b/src/utils.rs index 01fe9c1..75ff57c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -23,6 +23,13 @@ pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> { Ok(()) } +pub fn strip_cur_dir(source_path: &Path) -> PathBuf { + source_path + .strip_prefix(Component::CurDir) + .map(|path| path.to_path_buf()) + .unwrap_or_else(|_| source_path.to_path_buf()) +} + /// Changes the process' current directory to the directory that contains the /// file pointed to by `filename` and returns the directory that the process /// was in before this function was called. @@ -46,7 +53,7 @@ pub fn user_wants_to_overwrite(path: &Path, flags: &oof::Flags) -> crate::Result _ => {} } - let path = path.strip_prefix(Component::CurDir).unwrap_or_else(|_| path); + let path = strip_cur_dir(path); Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")).ask(Some(&to_utf(path))) }