mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-05 07:27:46 +00:00
chown,chgrp: fix bug in option --preserve-root
This commit is contained in:
parent
b6dcafc675
commit
09b0b9ad78
1 changed files with 6 additions and 5 deletions
|
@ -16,20 +16,21 @@ use std::io::Result as IOResult;
|
||||||
use std::path::{Component, Path, PathBuf};
|
use std::path::{Component, Path, PathBuf};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
pub fn resolve_relative_path<'a>(path: &'a Path) -> Cow<'a, Path> {
|
pub fn resolve_relative_path<'a>(path: &'a Path) -> Cow<'a, Path> {
|
||||||
if path.is_absolute() {
|
if path.components().all(|e| e != Component::ParentDir) {
|
||||||
return path.into();
|
return path.into();
|
||||||
}
|
}
|
||||||
let mut result = env::current_dir().unwrap_or(PathBuf::from("/"));
|
let root = Component::RootDir.as_os_str();
|
||||||
|
let mut result = env::current_dir().unwrap_or(PathBuf::from(root));
|
||||||
for comp in path.components() {
|
for comp in path.components() {
|
||||||
match comp {
|
match comp {
|
||||||
Component::ParentDir => {
|
Component::ParentDir => {
|
||||||
result.pop();
|
result.pop();
|
||||||
}
|
}
|
||||||
Component::CurDir => (),
|
Component::CurDir => (),
|
||||||
Component::Normal(s) => result.push(s),
|
Component::RootDir |
|
||||||
_ => unreachable!(),
|
Component::Normal(_) |
|
||||||
|
Component::Prefix(_) => result.push(comp.as_os_str()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.into()
|
result.into()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue