Reuse fixed file identity within a live alias scan
This commit is contained in:
1 parent
1c02d8af25
commit
24ea6ef7ee
4 files changed
+168
-32
No files matched your search
@@ -91,6 +91,13 @@ pub struct HostPreparation {
|
||||
#[serde(default)]
|
||||
pub generated_initial: Option<crate::native_generated::GeneratedInitialState>,
|
||||
}
|
||||
#[cfg(unix)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum UnixPathIdentity {
|
||||
Present(u64, u64),
|
||||
Missing,
|
||||
}
|
||||
|
||||
impl HostPreparation {
|
||||
pub(crate) fn environment(&mut self, name: &str) -> Option<OsString> {
|
||||
let value = std::env::var_os(name);
|
||||
@@ -141,6 +148,64 @@ impl HostPreparation {
|
||||
}
|
||||
pub(crate) fn same_file(&mut self, a: &Path, b: &Path) -> bool {
|
||||
let same = a == b || self.same_file_target(a, b);
|
||||
self.record_alias(a, b, same)
|
||||
}
|
||||
|
||||
pub(crate) fn aliases_any<'a>(
|
||||
&mut self,
|
||||
path: &Path,
|
||||
candidates: impl Iterator<Item = &'a Path> + Clone,
|
||||
) -> bool {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let mut candidates = candidates.peekable();
|
||||
let Some(first) = candidates.peek().copied() else {
|
||||
return false;
|
||||
};
|
||||
if path == first {
|
||||
return self.same_file(first, path);
|
||||
}
|
||||
if let Some(identity) = self.path_identity(path) {
|
||||
let same = candidates.clone().any(|candidate| {
|
||||
let alias = if candidate == path {
|
||||
true
|
||||
} else if identity == UnixPathIdentity::Missing {
|
||||
false
|
||||
} else if let Some(candidate_identity) = self.path_identity(candidate) {
|
||||
identity == candidate_identity
|
||||
} else {
|
||||
return self.same_file(candidate, path);
|
||||
};
|
||||
self.record_alias(candidate, path, alias)
|
||||
});
|
||||
// Keep observations local to this scan. If the fixed path
|
||||
// changed during a negative scan, use fresh pairwise probes.
|
||||
if same || self.path_identity(path) == Some(identity) {
|
||||
return same;
|
||||
}
|
||||
}
|
||||
return candidates.any(|candidate| self.same_file(candidate, path));
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
let mut candidates = candidates;
|
||||
candidates.any(|candidate| self.same_file(candidate, path))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn path_identity(&mut self, path: &Path) -> Option<UnixPathIdentity> {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
match self.metadata(path) {
|
||||
Ok(metadata) => Some(UnixPathIdentity::Present(metadata.dev(), metadata.ino())),
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => {
|
||||
Some(UnixPathIdentity::Missing)
|
||||
}
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn record_alias(&mut self, a: &Path, b: &Path, same: bool) -> bool {
|
||||
self.observations.push(HostObservation::Alias {
|
||||
left: a.into(),
|
||||
right: b.into(),
|
||||
|
||||
Reference in new issue
Block a user