From bbaf55eb3b30d8166091d57bedbdf687ebd6e34e Mon Sep 17 00:00:00 2001 From: Chummy Date: Fri, 20 Feb 2026 15:19:16 +0800 Subject: [PATCH] fix(config): harden sync_directory async signature across platforms --- src/config/schema.rs | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/config/schema.rs b/src/config/schema.rs index 7167ffb..88814aa 100644 --- a/src/config/schema.rs +++ b/src/config/schema.rs @@ -3528,20 +3528,23 @@ impl Config { } } -#[cfg(unix)] async fn sync_directory(path: &Path) -> Result<()> { - let dir = File::open(path) - .await - .with_context(|| format!("Failed to open directory for fsync: {}", path.display()))?; - dir.sync_all() - .await - .with_context(|| format!("Failed to fsync directory metadata: {}", path.display()))?; - Ok(()) -} + #[cfg(unix)] + { + let dir = File::open(path) + .await + .with_context(|| format!("Failed to open directory for fsync: {}", path.display()))?; + dir.sync_all() + .await + .with_context(|| format!("Failed to fsync directory metadata: {}", path.display()))?; + return Ok(()); + } -#[cfg(not(unix))] -async fn sync_directory(_path: &Path) -> Result<()> { - Ok(()) + #[cfg(not(unix))] + { + let _ = path; + Ok(()) + } } #[cfg(test)] @@ -3898,6 +3901,19 @@ tool_dispatcher = "xml" assert_eq!(parsed.agent.tool_dispatcher, "xml"); } + #[tokio::test] + async fn sync_directory_handles_existing_directory() { + let dir = std::env::temp_dir().join(format!( + "zeroclaw_test_sync_directory_{}", + uuid::Uuid::new_v4() + )); + fs::create_dir_all(&dir).await.unwrap(); + + sync_directory(&dir).await.unwrap(); + + let _ = fs::remove_dir_all(&dir).await; + } + #[tokio::test] async fn config_save_and_load_tmpdir() { let dir = std::env::temp_dir().join("zeroclaw_test_config");