Honor cancellation throughout publication recovery Git operations

This commit is contained in:
2026-11-02 22:20:53 +00:00
parent 9a7b9b9301
commit 04db23705a
10 changed files with 231 additions and 63 deletions

View File

@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"sort"
"strings"
@@ -26,11 +25,14 @@ func ListAttempts(ctx context.Context, repositoryDir, override string) (Attempts
repositoryDir = "."
}
result := AttemptsResult{Attempts: []Attempt{}, Diagnostics: []*RecoveryError{}}
if err := ctx.Err(); err != nil {
return result, recoveryFailure(ctx, "storage_enumeration", err)
}
var directory string
{
resolved, err := recordDirectoryFor(ctx, repositoryDir, override)
if err != nil {
return result, &RecoveryError{Kind: "storage_enumeration", cause: err}
return result, recoveryFailure(ctx, "storage_enumeration", err)
}
directory = resolved
}
@@ -40,7 +42,7 @@ func ListAttempts(ctx context.Context, repositoryDir, override string) (Attempts
}
entries, err := os.ReadDir(directory)
if err != nil {
return result, &RecoveryError{Kind: "storage_enumeration", cause: fmt.Errorf("enumerate records in %q: %w", directory, err)}
return result, recoveryFailure(ctx, "storage_enumeration", fmt.Errorf("enumerate records in %q: %w", directory, err))
}
paths := make([]string, 0, len(entries))
for _, entry := range entries {
@@ -75,17 +77,6 @@ func recordDirectoryFor(ctx context.Context, repositoryDir, override string) (st
if filepath.IsAbs(override) {
return filepath.Clean(override), nil
}
root, err := exec.CommandContext(ctx, "git", "-C", repositoryDir, "rev-parse", "--show-toplevel").Output()
if err != nil {
return "", err
}
rootPath := strings.TrimSpace(string(root))
if override != "" {
return filepath.Join(rootPath, override), nil
}
common, err := exec.CommandContext(ctx, "git", "-C", repositoryDir, "rev-parse", "--path-format=absolute", "--git-common-dir").Output()
if err != nil {
return "", err
}
return filepath.Join(strings.TrimSpace(string(common)), "releasekit", "publication-attempts"), nil
directory, _, err := resolveRecordDir(ctx, repositoryDir, override)
return directory, err
}