Retain discovered publication records when enumeration fails

This commit is contained in:
2026-11-02 22:41:18 +00:00
parent cd274512e7
commit 363f7cd513
7 changed files with 123 additions and 8 deletions

View File

@@ -22,6 +22,10 @@ type AttemptsResult struct {
}
func ListAttempts(ctx context.Context, repositoryDir, override string) (AttemptsResult, error) {
return listAttempts(ctx, repositoryDir, override, recordPaths)
}
func listAttempts(ctx context.Context, repositoryDir, override string, enumerate func(context.Context, string) ([]string, error)) (AttemptsResult, error) {
if repositoryDir == "" {
repositoryDir = "."
}
@@ -41,10 +45,7 @@ func ListAttempts(ctx context.Context, repositoryDir, override string) (Attempts
if err := ctx.Err(); err != nil {
return result, &RecoveryError{Kind: "canceled", cause: err}
}
paths, err := recordPaths(ctx, directory)
if err != nil {
return result, recoveryFailure(ctx, "storage_enumeration", fmt.Errorf("enumerate records in %q: %w", directory, err))
}
paths, enumerationErr := enumerate(ctx, directory)
sort.Strings(paths)
for _, path := range paths {
if err := ctx.Err(); err != nil {
@@ -65,6 +66,9 @@ func ListAttempts(ctx context.Context, repositoryDir, override string) (Attempts
}
result.Attempts = append(result.Attempts, Attempt{RecordPath: absolute, Evidence: evidence})
}
if enumerationErr != nil {
return result, recoveryFailure(ctx, "storage_enumeration", fmt.Errorf("enumerate records in %q: %w", directory, enumerationErr))
}
return result, nil
}
@@ -75,12 +79,16 @@ func recordPaths(ctx context.Context, directory string) ([]string, error) {
return nil, err
}
defer file.Close()
return readRecordPaths(ctx, directory, file.ReadDir)
}
func readRecordPaths(ctx context.Context, directory string, read func(int) ([]os.DirEntry, error)) ([]string, error) {
var paths []string
for {
if err := ctx.Err(); err != nil {
return paths, err
}
entries, err := file.ReadDir(128)
entries, err := read(128)
for _, entry := range entries {
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".json") {
paths = append(paths, filepath.Join(directory, entry.Name()))