mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
uucore/fs: call to_string_lossy only once
in dir_strip_dot_for_creation
This commit is contained in:
parent
64ba35b7f7
commit
69f671466f
1 changed files with 4 additions and 2 deletions
|
|
@ -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::<PathBuf>()
|
||||
Path::new(&path).components().collect()
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue