perf(sync): 限制暂存验证并复用已验证上传句柄

This commit is contained in:
2026-09-09 05:57:36 +08:00
parent b3b4feb2db
commit 6e261aa7e1
4 changed files with 127 additions and 33 deletions
+2 -9
View File
@@ -115,11 +115,7 @@ impl Workspace {
let digest = hash(bytes);
let path = self.sync_spool(&digest)?;
if path.exists() {
if fs::symlink_metadata(&path)?.file_type().is_symlink()
|| hash(&fs::read(&path)?) != digest
{
return Err(HostError::new("SYNC_SPOOL_CORRUPT"));
}
crate::payloads::verify(&path, &digest, bytes.len() as u64)?;
} else {
let mut temp = tempfile::NamedTempFile::new_in(path.parent().unwrap())?;
temp.write_all(bytes)?;
@@ -150,10 +146,7 @@ impl Workspace {
return Err(HostError::new("SYNC_CURSOR_INVALID"));
}
if let Some(digest) = &revision.hash {
let bytes = fs::read(self.sync_spool(digest)?)?;
if bytes.len() as i64 != revision.size || hash(&bytes) != *digest {
return Err(HostError::new("SYNC_SPOOL_CORRUPT"));
}
crate::payloads::verify(&self.sync_spool(digest)?, digest, revision.size as u64)?;
}
let encoded =
serde_json::to_string(revision).map_err(|_| HostError::new("SYNC_RESPONSE_INVALID"))?;