From 7b97b52af021500d8085c875d20215e8dc0f53cc Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 17 Nov 2025 11:49:49 +0800 Subject: feat: Add file status tracking and SHA1 hash system - Implement SHA1 hash calculation module with async support - Add file status analysis for tracking moves, creates, and modifications - Enhance local file management with relative path handling - Update virtual file actions with improved tracking capabilities --- crates/utils/string_proc/src/format_path.rs | 44 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'crates/utils/string_proc/src') diff --git a/crates/utils/string_proc/src/format_path.rs b/crates/utils/string_proc/src/format_path.rs index 2d8927b..a3493f5 100644 --- a/crates/utils/string_proc/src/format_path.rs +++ b/crates/utils/string_proc/src/format_path.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; /// Format path str pub fn format_path_str(path: impl Into) -> Result { let path_str = path.into(); + let ends_with_slash = path_str.ends_with('/'); // ANSI Strip let cleaned = strip_ansi_escapes::strip(&path_str); @@ -27,10 +28,43 @@ pub fn format_path_str(path: impl Into) -> Result PathBuf { + let mut components = Vec::new(); + + for component in path.components() { + match component { + std::path::Component::ParentDir => { + if !components.is_empty() { + components.pop(); + } + } + std::path::Component::CurDir => { + // Skip current directory components + } + _ => { + components.push(component); + } + } + } + + if components.is_empty() { + PathBuf::from(".") } else { - Ok(result) + components.iter().collect() } } @@ -58,6 +92,10 @@ mod tests { format_path_str("/home/user/file.txt")?, "/home/user/file.txt" ); + assert_eq!( + format_path_str("/home/my_user/DOCS/JVCS_TEST/Workspace/../Vault/")?, + "/home/my_user/DOCS/JVCS_TEST/Vault/" + ); Ok(()) } -- cgit