Skip to content

Commit

Permalink
uucore: drop unused function resolve_relative_path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BenWiederhake committed Mar 3, 2024
1 parent f87f229 commit 4bc6b83
Showing 1 changed file with 0 additions and 25 deletions.
25 changes: 0 additions & 25 deletions src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -195,30 +194,6 @@ impl Hash for FileInformation {
}
}

/// resolve a relative path
pub fn resolve_relative_path(path: &Path) -> Cow<Path> {
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 {
Expand Down

0 comments on commit 4bc6b83

Please sign in to comment.