Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions angrr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,23 @@ pub fn validate_store_path<P1: AsRef<Path>, P2: AsRef<Path>>(
store: P1,
target: P2,
) -> Option<PathBuf> {
let store = store.as_ref();
let target = target.as_ref();
match canonicalize_to_store(store, target) {
Ok(path) => Some(path),
match fs::canonicalize(target) {
Ok(path) => {
if path.starts_with(store) {
Some(path)
} else {
None
}
}
Err(e) => {
log::warn!("failed to canonicalize {target:?} for validation: {e}");
log::debug!("failed to canonicalize {target:?} for validation: {e}");
None
}
}
}

pub fn canonicalize_to_store<P1: AsRef<Path>, P2: AsRef<Path>>(
store: P1,
path: P2,
) -> anyhow::Result<PathBuf> {
let store = store.as_ref();
let path = path.as_ref();
if path.starts_with(store) {
Ok(PathBuf::from(path))
} else {
let metadata = fs::symlink_metadata(path)?;
if metadata.is_symlink() {
let next = fs::read_link(path)?;
canonicalize_to_store(store, next)
} else {
anyhow::bail!("canonicalized to a non-store path")
}
}
}

pub fn discover_users(roots: &[Arc<GcRoot>]) -> anyhow::Result<Vec<uzers::User>> {
let uids: BTreeSet<_> = roots.iter().map(|root| root.path_metadata.uid()).collect();
let mut users = Vec::new();
Expand Down