Propagate cancellation and preserve resumable state

This commit is contained in:
2026-11-20 05:53:49 +00:00
parent a6c6f1e4ab
commit c7a5ff316d
21 changed files with 356 additions and 27 deletions

View File

@@ -92,6 +92,9 @@ func cleanSelectedSession(ctx context.Context, input *cleanCommandInput, deps co
return report, err
}
appendTarget := func(root, target, policy string, directory bool) error {
if err := ctx.Err(); err != nil {
return err
}
action, err := cleanScopedTarget(root, target, policy, directory, input.DryRun)
report.Actions = append(report.Actions, action)
return err
@@ -100,7 +103,7 @@ func cleanSelectedSession(ctx context.Context, input *cleanCommandInput, deps co
if err := appendTarget(pipeline.Workspace.Root, filepath.Join(pipeline.Workspace.Root, config.PathWorkDirSegment), "clean.workspace.all", true); err != nil {
return report, err
}
actions, err := cleanRootChildren(pipeline.Spool.Root, "clean.spool.all", input.DryRun)
actions, err := cleanRootChildren(ctx, pipeline.Spool.Root, "clean.spool.all", input.DryRun)
report.Actions = append(report.Actions, actions...)
if err != nil {
return report, err
@@ -173,7 +176,7 @@ func cleanScopedTarget(root, target, policy string, directory, dryRun bool) (cle
return action, nil
}
func cleanRootChildren(root, policy string, dryRun bool) ([]cleanAction, error) {
func cleanRootChildren(ctx context.Context, root, policy string, dryRun bool) ([]cleanAction, error) {
rootAbs, entries, err := cleanableRootChildren(root, policy)
if err != nil {
return []cleanAction{{Path: root, Status: "failed", Error: err.Error()}}, err
@@ -183,6 +186,9 @@ func cleanRootChildren(root, policy string, dryRun bool) ([]cleanAction, error)
}
actions := make([]cleanAction, 0, len(entries))
for _, entry := range entries {
if err := ctx.Err(); err != nil {
return actions, err
}
action := cleanAction{Path: entry, Status: "would_delete"}
if !dryRun {
if err := fileops.RemoveAllUnderRoot(rootAbs, entry); err != nil {
@@ -213,6 +219,9 @@ func cleanSessionCache(ctx context.Context, cfg *config.Config, dryRun bool, dep
}
actions := []cleanAction{}
for _, object := range objects {
if err := ctx.Err(); err != nil {
return actions, err
}
key := strings.TrimSpace(object.Key)
if key == "" || strings.HasSuffix(key, "/") || !cleanIsFlac(key) {
continue