From d25d994125138dc84309727e51e9a2a5a5bc1e99 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sun, 3 Mar 2024 08:30:48 +0100 Subject: [PATCH] uucore: drop unused function resolve_relative_path This function is by necessity ill-defined: Depending on the context, '..' is either the logical parent directory, sometimes the physical parent directory. This function can only work for the latter case, in which case `Path::canonicalize` is often a better approach. --- src/uucore/src/lib/features/fs.rs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 6ed656380..c7fb1f2fc 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -13,7 +13,6 @@ use libc::{ S_IROTH, S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR, }; -use std::borrow::Cow; use std::collections::HashSet; use std::collections::VecDeque; use std::env; @@ -195,30 +194,6 @@ impl Hash for FileInformation { } } -/// resolve a relative path -pub fn resolve_relative_path(path: &Path) -> Cow { - if path.components().all(|e| e != Component::ParentDir) { - return path.into(); - } - let root = Component::RootDir.as_os_str(); - let mut result = env::current_dir().unwrap_or_else(|_| PathBuf::from(root)); - for comp in path.components() { - match comp { - Component::ParentDir => { - if let Ok(p) = result.read_link() { - result = p; - } - result.pop(); - } - Component::CurDir => (), - Component::RootDir | Component::Normal(_) | Component::Prefix(_) => { - result.push(comp.as_os_str()); - } - } - } - result.into() -} - /// Controls how symbolic links should be handled when canonicalizing a path. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum MissingHandling {