pub mod format;
pub use format::{OutputFormat, PmtilesOutput};
pub mod mbtiles;
pub use mbtiles::MbtilesOutput;
pub mod dedup;
pub mod directory;
pub mod hilbert;
pub mod writer;
pub fn sync_parent_dir(path: &std::path::Path) -> std::io::Result<()> {
#[cfg(unix)]
{
let parent = match path.parent() {
Some(p) if !p.as_os_str().is_empty() => p,
_ => std::path::Path::new("."),
};
std::fs::File::open(parent)?.sync_all()
}
#[cfg(not(unix))]
{
let _ = path;
Ok(())
}
}
#[cfg(test)]
mod sync_tests {
use super::sync_parent_dir;
#[test]
fn syncing_the_parent_of_a_new_file_succeeds() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("run.bin");
std::fs::write(&file, b"x").unwrap();
sync_parent_dir(&file).unwrap();
sync_parent_dir(std::path::Path::new("run-in-cwd.bin")).unwrap();
}
#[cfg(unix)]
#[test]
fn a_missing_parent_directory_is_an_error_not_a_silent_skip() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("gone").join("run.bin");
let err = sync_parent_dir(&file).expect_err("the folder does not exist");
assert_eq!(err.kind(), std::io::ErrorKind::NotFound);
}
}