mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
Merge pull request #1003 from Arcterus/fix-preserve-root
chgrp: fix more --preserve-root problems
This commit is contained in:
commit
a47d7d1a5b
2 changed files with 20 additions and 2 deletions
|
@ -217,6 +217,22 @@ impl Chgrper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn is_bind_root<P: AsRef<Path>>(&self, root: P) -> bool {
|
||||||
|
// TODO: is there an equivalent on Windows?
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn is_bind_root<P: AsRef<Path>>(&self, path: P) -> bool {
|
||||||
|
if let (Ok(given), Ok(root)) = (fs::metadata(path), fs::metadata("/")) {
|
||||||
|
given.dev() == root.dev() && given.ino() == root.ino()
|
||||||
|
} else {
|
||||||
|
// FIXME: not totally sure if it's okay to just ignore an error here
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn traverse<P: AsRef<Path>>(&self, root: P) -> i32 {
|
fn traverse<P: AsRef<Path>>(&self, root: P) -> i32 {
|
||||||
let follow_arg = self.dereference || self.bit_flag != FTS_PHYSICAL;
|
let follow_arg = self.dereference || self.bit_flag != FTS_PHYSICAL;
|
||||||
let path = root.as_ref();
|
let path = root.as_ref();
|
||||||
|
@ -244,7 +260,7 @@ impl Chgrper {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(p) = may_exist {
|
if let Some(p) = may_exist {
|
||||||
if p.parent().is_none() {
|
if p.parent().is_none() || self.is_bind_root(p) {
|
||||||
show_info!("it is dangerous to operate recursively on '/'");
|
show_info!("it is dangerous to operate recursively on '/'");
|
||||||
show_info!("use --no-preserve-root to override this failsafe");
|
show_info!("use --no-preserve-root to override this failsafe");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -14,7 +14,6 @@ use std::fs;
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::io::Result as IOResult;
|
use std::io::Result as IOResult;
|
||||||
use std::path::{Component, Path, PathBuf};
|
use std::path::{Component, Path, PathBuf};
|
||||||
#[cfg(unix)]
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub fn resolve_relative_path<'a>(path: &'a Path) -> Cow<'a, Path> {
|
pub fn resolve_relative_path<'a>(path: &'a Path) -> Cow<'a, Path> {
|
||||||
|
@ -26,6 +25,9 @@ pub fn resolve_relative_path<'a>(path: &'a Path) -> Cow<'a, Path> {
|
||||||
for comp in path.components() {
|
for comp in path.components() {
|
||||||
match comp {
|
match comp {
|
||||||
Component::ParentDir => {
|
Component::ParentDir => {
|
||||||
|
if let Ok(p) = result.read_link() {
|
||||||
|
result = p;
|
||||||
|
}
|
||||||
result.pop();
|
result.pop();
|
||||||
}
|
}
|
||||||
Component::CurDir => (),
|
Component::CurDir => (),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue