From 67dc07435d1a59fd3a768d3fbae0bc542998b11f Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Tue, 2 Jun 2026 18:58:18 +0000 Subject: [PATCH] Remove obsolete cleanup helpers --- internal/app/run_test.go | 8 +++--- internal/app/run_warnings.go | 8 ------ internal/storage/fake/backend.go | 42 ++++---------------------------- 3 files changed, 9 insertions(+), 49 deletions(-) diff --git a/internal/app/run_test.go b/internal/app/run_test.go index 0de1525..4373c7b 100644 --- a/internal/app/run_test.go +++ b/internal/app/run_test.go @@ -159,9 +159,9 @@ pipelines: } } -func TestWriteSSHWarningsReportsInsecureHostKeyPolicy(t *testing.T) { +func TestSSHWarningsReportInsecureHostKeyPolicy(t *testing.T) { var stdout bytes.Buffer - err := writeSSHWarnings(&stdout, config.Pipeline{ + err := writeWarnings(&stdout, sshWarnings(config.Pipeline{ ID: "reports", Source: config.Backend{ Backend: config.BackendSSH, @@ -172,9 +172,9 @@ func TestWriteSSHWarningsReportsInsecureHostKeyPolicy(t *testing.T) { Backend: config.BackendSSH, SSH: config.SSH{HostKeyPolicy: config.HostKeyPolicyOff}, }}, - }) + })) if err != nil { - t.Fatalf("writeSSHWarnings() error = %v", err) + t.Fatalf("writeWarnings() error = %v", err) } output := stdout.String() for _, want := range []string{ diff --git a/internal/app/run_warnings.go b/internal/app/run_warnings.go index 9ff827e..bd97d0d 100644 --- a/internal/app/run_warnings.go +++ b/internal/app/run_warnings.go @@ -7,10 +7,6 @@ import ( "gitea.maximumdirect.net/eric/distributor/internal/config" ) -func writeSecretConflictWarnings(w io.Writer, conflicts []config.SecretConflict) error { - return writeWarnings(w, secretConflictWarnings(conflicts)) -} - func secretConflictWarnings(conflicts []config.SecretConflict) []OutputWarning { warnings := make([]OutputWarning, 0, len(conflicts)) for _, conflict := range conflicts { @@ -21,10 +17,6 @@ func secretConflictWarnings(conflicts []config.SecretConflict) []OutputWarning { return warnings } -func writeSSHWarnings(w io.Writer, pipeline config.Pipeline) error { - return writeWarnings(w, sshWarnings(pipeline)) -} - func sshWarnings(pipeline config.Pipeline) []OutputWarning { var warnings []OutputWarning if pipeline.Source.Backend == config.BackendSSH && pipeline.Source.SSH.HostKeyPolicy == config.HostKeyPolicyOff { diff --git a/internal/storage/fake/backend.go b/internal/storage/fake/backend.go index 8014307..9ad7033 100644 --- a/internal/storage/fake/backend.go +++ b/internal/storage/fake/backend.go @@ -3,7 +3,6 @@ package fake import ( "bytes" "context" - "errors" "io" "sort" "strings" @@ -133,14 +132,14 @@ func (b *Backend) Walk(ctx context.Context, prefix string, opts storage.WalkOpti if err := storage.ValidatePrefix(prefix); err != nil { return err } + emitter := storage.NewWalkEmitter(ctx, backendName, opts, fn) if entry, err := b.Stat(ctx, prefix); err == nil && entry.Type != storage.EntryTypeDirectory { - return emit(ctx, entry, opts, fn) + return storage.FinishWalk(emitter.Emit(entry)) } else if err != nil && !storage.IsNotFound(err) { return err } entries := b.entries() - visited := 0 for _, entry := range entries { if entry.Path == "" || !entryBelow(prefix, entry.Path) { continue @@ -148,33 +147,15 @@ func (b *Backend) Walk(ctx context.Context, prefix string, opts storage.WalkOpti if !opts.Recursive && !isImmediateChild(prefix, entry.Path) { continue } - if opts.Limit > 0 && visited >= opts.Limit { - return nil - } - visited++ - if err := ctx.Err(); err != nil { - return err - } - if err := fn(entry); err != nil { - if errors.Is(err, storage.ErrStopWalk) { - return nil - } - return storage.NewError(storage.OpWalk, backendName, entry.Path, storage.ErrUnknown, err) + if err := emitter.Emit(entry); err != nil { + return storage.FinishWalk(err) } } return nil } func (b *Backend) HasAny(ctx context.Context, prefix string) (bool, error) { - found := false - err := b.Walk(ctx, prefix, storage.WalkOptions{Recursive: false, Limit: 1}, func(storage.Entry) error { - found = true - return storage.ErrStopWalk - }) - if err != nil { - return false, err - } - return found, nil + return storage.HasAny(ctx, b, prefix) } func (b *Backend) DeleteManagedBundle(ctx context.Context, bundlePath string, managedOutputPaths []string, opts storage.DeleteOptions) error { @@ -302,19 +283,6 @@ func (b *Backend) entries() []storage.Entry { return entries } -func emit(ctx context.Context, entry storage.Entry, opts storage.WalkOptions, fn storage.WalkFunc) error { - if opts.Limit > 0 && opts.Limit < 1 { - return nil - } - if err := ctx.Err(); err != nil { - return err - } - if err := fn(entry); err != nil && !errors.Is(err, storage.ErrStopWalk) { - return err - } - return nil -} - func entryBelow(prefix, path string) bool { if prefix == "" { return path != ""