mirror of
https://github.com/daeuniverse/honk.git
synced 2026-12-06 16:01:20 +00:00
fix(config): sync the current directory for a bare export filename
This commit is contained in:
2 files changed
+21
-3
No files matched your search
@@ -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<Option<(i64, Option<i64>)>, StoreError> {
|
||||
let Some(number) = head(connection)? else {
|
||||
return Ok(None);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user