fix(config): harden sync_directory async signature across platforms

This commit is contained in:
Chummy 2026-02-20 15:19:16 +08:00
parent 654f822430
commit bbaf55eb3b

View file

@ -3528,21 +3528,24 @@ impl Config {
} }
} }
#[cfg(unix)]
async fn sync_directory(path: &Path) -> Result<()> { async fn sync_directory(path: &Path) -> Result<()> {
#[cfg(unix)]
{
let dir = File::open(path) let dir = File::open(path)
.await .await
.with_context(|| format!("Failed to open directory for fsync: {}", path.display()))?; .with_context(|| format!("Failed to open directory for fsync: {}", path.display()))?;
dir.sync_all() dir.sync_all()
.await .await
.with_context(|| format!("Failed to fsync directory metadata: {}", path.display()))?; .with_context(|| format!("Failed to fsync directory metadata: {}", path.display()))?;
Ok(()) return Ok(());
} }
#[cfg(not(unix))] #[cfg(not(unix))]
async fn sync_directory(_path: &Path) -> Result<()> { {
let _ = path;
Ok(()) Ok(())
} }
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -3898,6 +3901,19 @@ tool_dispatcher = "xml"
assert_eq!(parsed.agent.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] #[tokio::test]
async fn config_save_and_load_tmpdir() { async fn config_save_and_load_tmpdir() {
let dir = std::env::temp_dir().join("zeroclaw_test_config"); let dir = std::env::temp_dir().join("zeroclaw_test_config");