diff --git a/crates/honk-core/src/native_api/store/db.rs b/crates/honk-core/src/native_api/store/db.rs index cde29e7e..0997a965 100644 --- a/crates/honk-core/src/native_api/store/db.rs +++ b/crates/honk-core/src/native_api/store/db.rs @@ -684,12 +684,17 @@ pub(crate) fn export_to(data_dir: &Path, out: &Path, with_secrets: bool) -> anyh .and_then(|()| std::fs::hard_link(&staged, out)); let _ = std::fs::remove_file(&staged); published.map_err(|error| anyhow::anyhow!("write {}: {error}", out.display()))?; - if let Some(parent) = out.parent().filter(|parent| !parent.as_os_str().is_empty()) { - File::open(parent)?.sync_all()?; - } + File::open(publication_dir(out))?.sync_all()?; Ok(()) } +/// A bare relative `out` has an empty parent, which names the current directory. +fn publication_dir(out: &Path) -> &Path { + out.parent() + .filter(|parent| !parent.as_os_str().is_empty()) + .unwrap_or(Path::new(".")) +} + fn head_and_parent(connection: &Connection) -> Result)>, StoreError> { let Some(number) = head(connection)? else { return Ok(None); diff --git a/crates/honk-core/src/native_api/store/db/tests.rs b/crates/honk-core/src/native_api/store/db/tests.rs index ae17abd8..e98f3738 100644 --- a/crates/honk-core/src/native_api/store/db/tests.rs +++ b/crates/honk-core/src/native_api/store/db/tests.rs @@ -220,6 +220,19 @@ fn cli_export_restores_secrets_into_a_new_private_file() { assert_eq!(store.head(), Ok(Some(1))); } +#[test] +fn export_syncs_the_current_directory_for_a_bare_filename() { + assert_eq!(publication_dir(Path::new("exported.dae")), Path::new(".")); + assert_eq!( + publication_dir(Path::new("out/exported.dae")), + Path::new("out") + ); + assert_eq!( + publication_dir(Path::new("/tmp/exported.dae")), + Path::new("/tmp") + ); +} + #[test] fn head_cache_and_existence_follow_promote() { let fixture = fixture();