feat: support cancellable official sync

This commit is contained in:
2026-07-10 00:36:40 +08:00
parent f704ec18c5
commit 2bdc55a1be
4 changed files with 188 additions and 20 deletions
+19
View File
@@ -332,6 +332,17 @@ impl OfficialResourcePullService {
&self,
plan: &OfficialResourcePullPlan,
mut progress: impl FnMut(OfficialResourcePullProgress),
) -> Result<OfficialResourcePullReport, String> {
self.pull_with_progress_and_cancellation(plan, &mut progress, || false)
}
/// Executes the plan, emits URL progress, and aborts between URLs when
/// `should_cancel` returns true.
pub fn pull_with_progress_and_cancellation(
&self,
plan: &OfficialResourcePullPlan,
mut progress: impl FnMut(OfficialResourcePullProgress),
mut should_cancel: impl FnMut() -> bool,
) -> Result<OfficialResourcePullReport, String> {
fs::create_dir_all(&self.output_root).map_err(|error| {
format!(
@@ -347,6 +358,10 @@ impl OfficialResourcePullService {
let total = urls.len();
let mut items = Vec::new();
for (offset, url) in urls.into_iter().enumerate() {
if should_cancel() {
return Err("official resource pull interrupted by shutdown request".to_string());
}
let index = offset + 1;
progress(OfficialResourcePullProgress::started(
index,
@@ -400,6 +415,10 @@ impl OfficialResourcePullService {
});
}
if should_cancel() {
return Err("official resource pull interrupted by shutdown request".to_string());
}
let verified_hashes = self.verify_downloaded_official_hashes(&official_hash_pairs)?;
Ok(OfficialResourcePullReport {