diff --git a/crates/ghostlight/src/vault.rs b/crates/ghostlight/src/vault.rs index b312be2..c545deb 100644 --- a/crates/ghostlight/src/vault.rs +++ b/crates/ghostlight/src/vault.rs @@ -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 { 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();