Sync the changed ledger alongside native draft artifacts

This commit is contained in:
gloamxun committed 2026-11-26 22:05:08 +08:00
1 parent 140bb19849
commit 1307bbcf0c
2 files changed
+58 -5

No files matched your search

+24 -5
View File
@@ -1315,8 +1315,18 @@ impl PendingDraft {
}
Ok(())
};
// Flush independent files concurrently, then finish collecting all
// results before the revision gate can install any artifact.
let sync_ledger = || -> Result<(), String> {
if let Some(ledger) = &draft.ledger
&& !cancellation.is_cancelled()
{
ledger.file.sync_all().map_err(|e| {
format!("sync native draft ledger {}: {e}", draft.ledger_target.path.display())
})?;
}
Ok(())
};
// Flush independent files concurrently and collect all results
// before the revision gate can install any artifact.
std::thread::scope(|scope| {
let pdf_worker = pdf
.as_ref()
@@ -1331,6 +1341,11 @@ impl PendingDraft {
.spawn_scoped(scope, sync_log)
.ok()
});
let ledger_worker = draft.ledger.as_ref().and_then(|_| {
std::thread::Builder::new()
.spawn_scoped(scope, sync_ledger)
.ok()
});
let generated = artifacts.iter().try_for_each(|artifact| {
if cancellation.is_cancelled() {
return Ok(());
@@ -1356,7 +1371,12 @@ impl PendingDraft {
.join()
.map_err(|_| "native draft log sync thread panicked".to_owned())?
});
pdf_result.and(log_result).and(generated)
let ledger_result = ledger_worker.map_or_else(sync_ledger, |worker| {
worker
.join()
.map_err(|_| "native draft ledger sync thread panicked".to_owned())?
});
pdf_result.and(log_result).and(generated).and(ledger_result)
})?;
drop(log);
if cancellation.is_cancelled() {
@@ -1364,6 +1384,7 @@ impl PendingDraft {
}
artifacts.push(draft.log);
let untouched_ledger = if let Some(DraftLedger { file, staged }) = draft.ledger {
// Verify the final staged bytes after the other syncs finish.
let target = &draft.ledger_target.path;
let actual = fs::symlink_metadata(&staged.path).map_err(|e| e.to_string())?;
let descriptor = file.metadata().map_err(|e| e.to_string())?;
@@ -1377,8 +1398,6 @@ impl PendingDraft {
target.display()
));
}
file.sync_all()
.map_err(|e| format!("sync native draft ledger {}: {e}", target.display()))?;
drop(file);
artifacts.push(DraftArtifact {
target: draft.ledger_target,