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,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");