Skip to content

Commit 0f40302

Browse files
authored
Merge pull request #8399 from cakebaker/uucore_fs_create_single_string
uucore/fs: call `to_string_lossy` only once in `dir_strip_dot_for_creation`
2 parents 64ba35b + 69f6714 commit 0f40302

File tree

1 file changed

+4
-2
lines changed
  • src/uucore/src/lib/features

1 file changed

+4
-2
lines changed

src/uucore/src/lib/features/fs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,11 @@ pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String
539539
/// install -d foo/. (and foo/./) should work and just create foo/
540540
/// std::fs::create_dir("foo/."); fails in pure Rust
541541
pub fn dir_strip_dot_for_creation(path: &Path) -> PathBuf {
542-
if path.to_string_lossy().ends_with("/.") || path.to_string_lossy().ends_with("/./") {
542+
let path_str = path.to_string_lossy();
543+
544+
if path_str.ends_with("/.") || path_str.ends_with("/./") {
543545
// Do a simple dance to strip the "/."
544-
Path::new(&path).components().collect::<PathBuf>()
546+
Path::new(&path).components().collect()
545547
} else {
546548
path.to_path_buf()
547549
}

0 commit comments

Comments
 (0)