From 0e7c964af5995289c41d9cc613db3e9567da23f5 Mon Sep 17 00:00:00 2001 From: mrbeanc Date: Sun, 24 Dec 2023 22:30:58 +0800 Subject: [PATCH] =?UTF-8?q?del:=20=E5=88=A0=E9=99=A4unify=5Fpath=5Fseparat?= =?UTF-8?q?or()=EF=BC=8C=E5=8F=AA=E6=9C=89=E6=B5=8B=E8=AF=95=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E8=BE=93=E5=85=A5=E4=BC=9A=E5=87=BA=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=88=B7=E8=BE=93=E5=85=A5=E8=82=AF=E5=AE=9A?= =?UTF-8?q?=E9=83=BD=E6=98=AF=E5=AF=B9=E5=BA=94=E5=B9=B3=E5=8F=B0=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E7=89=B9=E6=AE=8A=E5=A4=84=E7=90=86?= =?UTF-8?q?=E8=B7=A8=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/util.rs | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/src/utils/util.rs b/src/utils/util.rs index 4255b80..d81424a 100644 --- a/src/utils/util.rs +++ b/src/utils/util.rs @@ -108,7 +108,7 @@ pub fn check_repo_exist() { panic!("不是合法的mit仓库"); } } - +// TODO 拆分为PathExt.rs,并定义为trait,实现PathBuf的扩展方法 /// 获取.mit目录路径 pub fn get_storage_path() -> Result { /*递归获取储存库 */ @@ -223,22 +223,9 @@ pub fn format_time(time: &std::time::SystemTime) -> String { datetime.format("%Y-%m-%d %H:%M:%S.%3f").to_string() } -/// 将路径中的分隔符统一为当前系统的分隔符 -fn unify_path_separator(path: &Path) -> PathBuf { - #[cfg(windows)] - { - path.to_string_lossy().replace("/", "\\").into() - } - #[cfg(not(windows))] - { - path.to_string_lossy().replace("\\", "/").into() - } -} - /// 递归遍历给定目录及其子目录,列出所有文件,除了.mit pub fn list_files(path: &Path) -> io::Result> { let mut files = Vec::new(); - let path = unify_path_separator(path); if path.is_dir() { if path.file_name().unwrap_or_default() == ROOT_DIR { // 跳过 .mit 目录 @@ -562,7 +549,7 @@ mod tests { let rel_path = get_relative_path(&path, &cur_dir()); println!("{:?}", rel_path); - assert_eq!(rel_path, unify_path_separator(path)); + assert_eq!(rel_path, path); } #[test] @@ -595,18 +582,6 @@ mod tests { println!("{}", formatted_time); } - #[test] - fn test_unify_path_separator() { - let path_str = "src/utils\\aaa.rs"; - let path = unify_path_separator(Path::new(path_str)); - println!("{}", path.display()); - - #[cfg(windows)] - assert_eq!(path, Path::new("src\\utils\\aaa.rs")); - #[cfg(not(windows))] - assert_eq!(path, Path::new("src/utils/aaa.rs")); - } - #[test] fn test_list_files() { setup_test_with_clean_mit();