1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 04:57:45 +00:00

chgrp: detect bind mounted root

This commit is contained in:
Arcterus 2016-11-28 02:41:40 -08:00
parent 3ab82f9a66
commit f5fce8dadb

View file

@ -217,6 +217,21 @@ impl Chgrper {
}
}
#[cfg(windows)]
fn is_bind_root<P: AsRef<Path>>(&self, root: P) -> bool {
false
}
#[cfg(unix)]
fn is_bind_root<P: AsRef<Path>>(&self, path: P) -> bool {
use std::os::unix::fs::MetadataExt;
// FIXME: remove unwrap here
let given = std::fs::metadata(path).unwrap();
let root = std::fs::metadata("/").unwrap();
given.dev() == root.dev() && given.ino() == root.ino()
}
fn traverse<P: AsRef<Path>>(&self, root: P) -> i32 {
let follow_arg = self.dereference || self.bit_flag != FTS_PHYSICAL;
let path = root.as_ref();
@ -244,7 +259,7 @@ impl Chgrper {
};
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!("use --no-preserve-root to override this failsafe");
return 1;