Remove obsolete cleanup helpers
This commit is contained in:
@@ -159,9 +159,9 @@ pipelines:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWriteSSHWarningsReportsInsecureHostKeyPolicy(t *testing.T) {
|
func TestSSHWarningsReportInsecureHostKeyPolicy(t *testing.T) {
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
err := writeSSHWarnings(&stdout, config.Pipeline{
|
err := writeWarnings(&stdout, sshWarnings(config.Pipeline{
|
||||||
ID: "reports",
|
ID: "reports",
|
||||||
Source: config.Backend{
|
Source: config.Backend{
|
||||||
Backend: config.BackendSSH,
|
Backend: config.BackendSSH,
|
||||||
@@ -172,9 +172,9 @@ func TestWriteSSHWarningsReportsInsecureHostKeyPolicy(t *testing.T) {
|
|||||||
Backend: config.BackendSSH,
|
Backend: config.BackendSSH,
|
||||||
SSH: config.SSH{HostKeyPolicy: config.HostKeyPolicyOff},
|
SSH: config.SSH{HostKeyPolicy: config.HostKeyPolicyOff},
|
||||||
}},
|
}},
|
||||||
})
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("writeSSHWarnings() error = %v", err)
|
t.Fatalf("writeWarnings() error = %v", err)
|
||||||
}
|
}
|
||||||
output := stdout.String()
|
output := stdout.String()
|
||||||
for _, want := range []string{
|
for _, want := range []string{
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/distributor/internal/config"
|
"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 {
|
func secretConflictWarnings(conflicts []config.SecretConflict) []OutputWarning {
|
||||||
warnings := make([]OutputWarning, 0, len(conflicts))
|
warnings := make([]OutputWarning, 0, len(conflicts))
|
||||||
for _, conflict := range conflicts {
|
for _, conflict := range conflicts {
|
||||||
@@ -21,10 +17,6 @@ func secretConflictWarnings(conflicts []config.SecretConflict) []OutputWarning {
|
|||||||
return warnings
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSSHWarnings(w io.Writer, pipeline config.Pipeline) error {
|
|
||||||
return writeWarnings(w, sshWarnings(pipeline))
|
|
||||||
}
|
|
||||||
|
|
||||||
func sshWarnings(pipeline config.Pipeline) []OutputWarning {
|
func sshWarnings(pipeline config.Pipeline) []OutputWarning {
|
||||||
var warnings []OutputWarning
|
var warnings []OutputWarning
|
||||||
if pipeline.Source.Backend == config.BackendSSH && pipeline.Source.SSH.HostKeyPolicy == config.HostKeyPolicyOff {
|
if pipeline.Source.Backend == config.BackendSSH && pipeline.Source.SSH.HostKeyPolicy == config.HostKeyPolicyOff {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package fake
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -133,14 +132,14 @@ func (b *Backend) Walk(ctx context.Context, prefix string, opts storage.WalkOpti
|
|||||||
if err := storage.ValidatePrefix(prefix); err != nil {
|
if err := storage.ValidatePrefix(prefix); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
emitter := storage.NewWalkEmitter(ctx, backendName, opts, fn)
|
||||||
if entry, err := b.Stat(ctx, prefix); err == nil && entry.Type != storage.EntryTypeDirectory {
|
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) {
|
} else if err != nil && !storage.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
entries := b.entries()
|
entries := b.entries()
|
||||||
visited := 0
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if entry.Path == "" || !entryBelow(prefix, entry.Path) {
|
if entry.Path == "" || !entryBelow(prefix, entry.Path) {
|
||||||
continue
|
continue
|
||||||
@@ -148,33 +147,15 @@ func (b *Backend) Walk(ctx context.Context, prefix string, opts storage.WalkOpti
|
|||||||
if !opts.Recursive && !isImmediateChild(prefix, entry.Path) {
|
if !opts.Recursive && !isImmediateChild(prefix, entry.Path) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if opts.Limit > 0 && visited >= opts.Limit {
|
if err := emitter.Emit(entry); err != nil {
|
||||||
return nil
|
return storage.FinishWalk(err)
|
||||||
}
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backend) HasAny(ctx context.Context, prefix string) (bool, error) {
|
func (b *Backend) HasAny(ctx context.Context, prefix string) (bool, error) {
|
||||||
found := false
|
return storage.HasAny(ctx, b, prefix)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backend) DeleteManagedBundle(ctx context.Context, bundlePath string, managedOutputPaths []string, opts storage.DeleteOptions) error {
|
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
|
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 {
|
func entryBelow(prefix, path string) bool {
|
||||||
if prefix == "" {
|
if prefix == "" {
|
||||||
return path != ""
|
return path != ""
|
||||||
|
|||||||
Reference in New Issue
Block a user