vault: relative_dir drops the redundant is_absolute arm; test an import that cannot publish

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 19:55:23 +01:00
commit 03fb33fb93

View file

@ -406,10 +406,9 @@ fn hex(bytes: &[u8]) -> String {
/// when it is absolute or holds anything but plain components.
fn relative_dir(text: &str) -> Option<String> {
let path = Path::new(text.trim());
if path.is_absolute()
|| path
.components()
.any(|part| !matches!(part, Component::Normal(_)))
if path
.components()
.any(|part| !matches!(part, Component::Normal(_)))
{
return None;
}
@ -1482,6 +1481,19 @@ mod tests {
}
}
/// An import that cannot publish says so: a directory squatting on the
/// snapshot's name is an error, not a snapshot already held.
#[test]
fn an_import_that_cannot_publish_is_an_error() {
let vault = fixture();
let built = snapshot(vault.path());
let store = tempfile::tempdir().unwrap();
let squatter = store.path().join(format!("{}.cc", built.id()));
std::fs::create_dir_all(squatter.join("inside")).unwrap();
assert!(matches!(built.import_into(store.path()), Err(VaultError::Store)));
assert_eq!(listing(store.path()), [format!("{}.cc", built.id())]);
}
#[test]
fn load_leaves_the_store_directory_as_it_found_it() {
let vault = fixture();