Resolve ordinary leaves under verified project parents directly
This commit is contained in:
1 parent
7164b1915a
commit
128f0681f6
2 files changed
+69
-14
No files matched your search
@@ -401,10 +401,52 @@ impl ProjectSnapshot {
|
||||
fn covered(&self, path: &Path) -> bool {
|
||||
self.roots.iter().any(|root| path.starts_with(root))
|
||||
}
|
||||
fn node_kind(&self, path: &Path, live: &BTreeSet<PathBuf>) -> Option<NodeKind> {
|
||||
if self.directories.contains(path) {
|
||||
Some(NodeKind::Directory)
|
||||
} else if self.files.contains_key(path) || live.contains(path) {
|
||||
Some(NodeKind::File)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
#[cfg(unix)]
|
||||
fn has_plain_declared_parent(&self, path: &Path) -> bool {
|
||||
let Some(parent) = path.parent().and_then(|parent| self.directories.get(parent)) else {
|
||||
return false;
|
||||
};
|
||||
// A declared directory's ancestors are directories, too. Check the
|
||||
// original byte spelling before bypassing traversal: Path equality
|
||||
// can ignore separators and ordinary dot components.
|
||||
let parent = parent.as_os_str().as_encoded_bytes();
|
||||
let Some(tail) = path.as_os_str().as_encoded_bytes().strip_prefix(parent) else {
|
||||
return false;
|
||||
};
|
||||
let leaf = if parent == b"/" {
|
||||
tail
|
||||
} else {
|
||||
let Some(leaf) = tail.strip_prefix(b"/") else {
|
||||
return false;
|
||||
};
|
||||
leaf
|
||||
};
|
||||
!leaf.is_empty() && leaf != b"." && leaf != b".." && !leaf.contains(&b'/')
|
||||
}
|
||||
pub(super) fn locate(&self, path: &Path, live: &BTreeSet<PathBuf>) -> Result<Location, String> {
|
||||
if !path.is_absolute() {
|
||||
return Err("atomic project lookup must be absolute".into());
|
||||
}
|
||||
#[cfg(unix)]
|
||||
if self.has_plain_declared_parent(path) && !self.aliases.contains_key(path) {
|
||||
let kind = self.node_kind(path, live);
|
||||
if kind.is_some() || self.covered(path) {
|
||||
return Ok(Location {
|
||||
path: path.to_owned(),
|
||||
kind,
|
||||
final_component: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
let mut queue = lookup_components(path);
|
||||
let mut current = PathBuf::new();
|
||||
let mut links = 0;
|
||||
@@ -433,13 +475,7 @@ impl ProjectSnapshot {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let kind = if self.directories.contains(¤t) {
|
||||
Some(NodeKind::Directory)
|
||||
} else if self.files.contains_key(¤t) || live.contains(¤t) {
|
||||
Some(NodeKind::File)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let kind = self.node_kind(¤t, live);
|
||||
if kind == Some(NodeKind::File) && !queue.is_empty() {
|
||||
return Err(format!(
|
||||
"atomic project path traverses a file: {}",
|
||||
@@ -460,13 +496,7 @@ impl ProjectSnapshot {
|
||||
});
|
||||
}
|
||||
}
|
||||
let kind = if self.directories.contains(¤t) {
|
||||
Some(NodeKind::Directory)
|
||||
} else if self.files.contains_key(¤t) || live.contains(¤t) {
|
||||
Some(NodeKind::File)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let kind = self.node_kind(¤t, live);
|
||||
if kind == Some(NodeKind::File)
|
||||
&& path
|
||||
.as_os_str()
|
||||
|
||||
Reference in new issue
Block a user