From 69f671466fa38f960d3fa6efda043c1c2332d1d2 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sun, 27 Jul 2025 16:16:04 +0200 Subject: [PATCH] uucore/fs: call to_string_lossy only once in dir_strip_dot_for_creation --- src/uucore/src/lib/features/fs.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 54b74428e..e112bf730 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -539,9 +539,11 @@ pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String /// install -d foo/. (and foo/./) should work and just create foo/ /// std::fs::create_dir("foo/."); fails in pure Rust pub fn dir_strip_dot_for_creation(path: &Path) -> PathBuf { - if path.to_string_lossy().ends_with("/.") || path.to_string_lossy().ends_with("/./") { + let path_str = path.to_string_lossy(); + + if path_str.ends_with("/.") || path_str.ends_with("/./") { // Do a simple dance to strip the "/." - Path::new(&path).components().collect::() + Path::new(&path).components().collect() } else { path.to_path_buf() }