Fix cancelPackage not removing packages from session
cancelPackage only marked packages/items as cancelled but never removed them from session.packages, session.items, or session.packageOrder. The old download-manager called removePackageFromSession() which actually deletes the entries. Now cancelPackage properly removes all items and the package from the session, cleans up related state, and runs artifact cleanup in the background. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ab08506361
commit
3567cc173c
@ -523,23 +523,37 @@ export class DownloadManager extends EventEmitter {
|
||||
pkg.cancelled = true;
|
||||
pkg.status = "cancelled";
|
||||
pkg.updatedAt = nowMs();
|
||||
for (const itemId of pkg.itemIds) {
|
||||
const outputDir = pkg.outputDir;
|
||||
const itemIds = [...pkg.itemIds];
|
||||
|
||||
for (const itemId of itemIds) {
|
||||
const item = this.session.items[itemId];
|
||||
if (!item) continue;
|
||||
const slot = this.activeTasks.get(itemId);
|
||||
if (slot) { slot.abortReason = "cancel"; slot.abortController.abort("cancel"); }
|
||||
if (!isFinishedStatus(item.status)) {
|
||||
item.status = "cancelled";
|
||||
item.fullStatus = "Abgebrochen";
|
||||
item.speedBps = 0;
|
||||
item.updatedAt = nowMs();
|
||||
if (item.status !== "completed") {
|
||||
this.runOutcomes.set(itemId, "cancelled");
|
||||
}
|
||||
this.releaseTargetPath(itemId);
|
||||
this.retryManager.removeItem(itemId);
|
||||
this.cachedDirectUrls.delete(itemId);
|
||||
this.itemContributedBytes.delete(itemId);
|
||||
delete this.session.items[itemId];
|
||||
this.itemCount = Math.max(0, this.itemCount - 1);
|
||||
}
|
||||
|
||||
this.postProcessor.abortPackage(packageId);
|
||||
this.historyRecordedPackages.delete(packageId);
|
||||
this.hybridExtractRequeue.delete(packageId);
|
||||
this.packagePostProcessTasks.delete(packageId);
|
||||
delete this.session.packages[packageId];
|
||||
this.session.packageOrder = this.session.packageOrder.filter(id => id !== packageId);
|
||||
|
||||
this.persistSoon();
|
||||
this.emitState();
|
||||
|
||||
// Cleanup artifacts in background
|
||||
void cleanupCancelledPackageArtifactsAsync(outputDir).catch(() => {});
|
||||
}
|
||||
|
||||
public resetPackage(packageId: string): void {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user