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 {
|
fn covered(&self, path: &Path) -> bool {
|
||||||
self.roots.iter().any(|root| path.starts_with(root))
|
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> {
|
pub(super) fn locate(&self, path: &Path, live: &BTreeSet<PathBuf>) -> Result<Location, String> {
|
||||||
if !path.is_absolute() {
|
if !path.is_absolute() {
|
||||||
return Err("atomic project lookup must be absolute".into());
|
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 queue = lookup_components(path);
|
||||||
let mut current = PathBuf::new();
|
let mut current = PathBuf::new();
|
||||||
let mut links = 0;
|
let mut links = 0;
|
||||||
@@ -433,13 +475,7 @@ impl ProjectSnapshot {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let kind = if self.directories.contains(¤t) {
|
let kind = self.node_kind(¤t, live);
|
||||||
Some(NodeKind::Directory)
|
|
||||||
} else if self.files.contains_key(¤t) || live.contains(¤t) {
|
|
||||||
Some(NodeKind::File)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
if kind == Some(NodeKind::File) && !queue.is_empty() {
|
if kind == Some(NodeKind::File) && !queue.is_empty() {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"atomic project path traverses a file: {}",
|
"atomic project path traverses a file: {}",
|
||||||
@@ -460,13 +496,7 @@ impl ProjectSnapshot {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let kind = if self.directories.contains(¤t) {
|
let kind = self.node_kind(¤t, live);
|
||||||
Some(NodeKind::Directory)
|
|
||||||
} else if self.files.contains_key(¤t) || live.contains(¤t) {
|
|
||||||
Some(NodeKind::File)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
if kind == Some(NodeKind::File)
|
if kind == Some(NodeKind::File)
|
||||||
&& path
|
&& path
|
||||||
.as_os_str()
|
.as_os_str()
|
||||||
|
|||||||
@@ -247,6 +247,9 @@ fn directory_aliases_parent_components_and_unknown_universe_follow_declared_name
|
|||||||
file(&mut d, p.join("real/parent.tex"), b"RIGHT");
|
file(&mut d, p.join("real/parent.tex"), b"RIGHT");
|
||||||
file(&mut d, p.join("parent.tex"), b"WRONG");
|
file(&mut d, p.join("parent.tex"), b"WRONG");
|
||||||
d.aliases.insert(p.join("link"), "real/child".into());
|
d.aliases.insert(p.join("link"), "real/child".into());
|
||||||
|
#[cfg(unix)]
|
||||||
|
d.aliases
|
||||||
|
.insert(p.join("file-alias.tex"), "real/parent.tex".into());
|
||||||
d.aliases
|
d.aliases
|
||||||
.insert(p.join("file-dot"), "real/parent.tex/.".into());
|
.insert(p.join("file-dot"), "real/parent.tex/.".into());
|
||||||
d.aliases
|
d.aliases
|
||||||
@@ -285,6 +288,28 @@ fn directory_aliases_parent_components_and_unknown_universe_follow_declared_name
|
|||||||
w.read(ResourceKind::Tex, "./real/parent.tex/", &p.join("main.tex"))
|
w.read(ResourceKind::Tex, "./real/parent.tex/", &p.join("main.tex"))
|
||||||
.is_err()
|
.is_err()
|
||||||
);
|
);
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
let canonical = p.join("real/parent.tex");
|
||||||
|
for spelling in [
|
||||||
|
"real/parent.tex",
|
||||||
|
"real//parent.tex",
|
||||||
|
"real/./parent.tex",
|
||||||
|
"file-alias.tex",
|
||||||
|
] {
|
||||||
|
let raw = p.join(spelling);
|
||||||
|
let resource = w
|
||||||
|
.read(ResourceKind::Tex, raw.to_str().unwrap(), &p.join("main.tex"))
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(resource.data, b"RIGHT");
|
||||||
|
let lookup = w.trace().lookups.last().unwrap();
|
||||||
|
assert_eq!(lookup.candidates[0].as_os_str(), raw.as_os_str());
|
||||||
|
assert_eq!(
|
||||||
|
lookup.resolved.as_deref().unwrap().as_os_str(),
|
||||||
|
canonical.as_os_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
for name in ["./real/parent.tex/.", "file-dot", "file-slash"] {
|
for name in ["./real/parent.tex/.", "file-dot", "file-slash"] {
|
||||||
assert!(
|
assert!(
|
||||||
w.read(ResourceKind::Tex, name, &p.join("main.tex"))
|
w.read(ResourceKind::Tex, name, &p.join("main.tex"))
|
||||||
|
|||||||
Reference in new issue
Block a user