From 9d1ded301e506e6e11cfc77fb3f36577c8e6a687 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sun, 31 May 2026 03:41:56 +0000 Subject: [PATCH] Remove stale cleanup leftovers --- internal/app/app.go | 4 ---- internal/app/inspect.go | 10 ++-------- internal/app/pipeline.go | 5 ----- internal/app/run.go | 15 ++++++++------- internal/bundle/discover.go | 4 ++-- internal/bundle/validate.go | 23 ++++++++--------------- internal/cli/root.go | 5 ----- internal/publish/plan.go | 7 ------- internal/publish/safety.go | 2 +- internal/storage/path.go | 7 +++++++ internal/storage/path_test.go | 14 ++++++++++++++ 11 files changed, 42 insertions(+), 54 deletions(-) delete mode 100644 internal/app/pipeline.go diff --git a/internal/app/app.go b/internal/app/app.go index 2c4000c..fb655d1 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1,14 +1,10 @@ package app -import "errors" - const Name = "distributor" // Version can be replaced at build time with -ldflags "-X .../internal/app.Version=". var Version = "dev" -var ErrNotImplemented = errors.New("not implemented") - func VersionString() string { return Name + " " + Version } diff --git a/internal/app/inspect.go b/internal/app/inspect.go index cb2b511..7b1ec68 100644 --- a/internal/app/inspect.go +++ b/internal/app/inspect.go @@ -6,6 +6,7 @@ import ( "io" "gitea.maximumdirect.net/eric/distributor/internal/bundle" + "gitea.maximumdirect.net/eric/distributor/internal/storage" ) type InspectOptions struct { @@ -39,7 +40,7 @@ func writeInspection(w io.Writer, bundles []bundle.Bundle) error { if _, err := fmt.Fprintf( w, "- path=%s id=%s created=%s digest=%s files=%d\n", - displayBundlePath(sourceBundle.RootRelativePath), + storage.DisplayPath(sourceBundle.RootRelativePath), sourceBundle.Manifest.ID, sourceBundle.Manifest.Created.Format("2006-01-02T15:04:05Z07:00"), sourceBundle.Manifest.Digest, @@ -55,10 +56,3 @@ func writeInspection(w io.Writer, bundles []bundle.Bundle) error { } return nil } - -func displayBundlePath(path string) string { - if path == "" { - return "." - } - return path -} diff --git a/internal/app/pipeline.go b/internal/app/pipeline.go deleted file mode 100644 index 60d396b..0000000 --- a/internal/app/pipeline.go +++ /dev/null @@ -1,5 +0,0 @@ -package app - -type Pipeline struct { - ID string -} diff --git a/internal/app/run.go b/internal/app/run.go index 38dc1e3..22fcd19 100644 --- a/internal/app/run.go +++ b/internal/app/run.go @@ -11,6 +11,7 @@ import ( "gitea.maximumdirect.net/eric/distributor/internal/config" "gitea.maximumdirect.net/eric/distributor/internal/notify" "gitea.maximumdirect.net/eric/distributor/internal/publish" + "gitea.maximumdirect.net/eric/distributor/internal/storage" ) type RunOptions struct { @@ -68,7 +69,7 @@ func runConfig(ctx context.Context, cfg config.Config, options RunOptions) error for _, destination := range pipeline.Destinations { destinationBackend, err := backends.openDestination(ctx, destination) if err != nil { - failures.add(pipeline.ID, destination.ID, displayBundlePath(sourceBundle.RootRelativePath), err) + failures.add(pipeline.ID, destination.ID, storage.DisplayPath(sourceBundle.RootRelativePath), err) summary.recordFailure() if options.Stdout != nil { writeErrorLine(options.Stdout, sourceBundle.RootRelativePath, destination.ID, err) @@ -96,20 +97,20 @@ func runConfig(ctx context.Context, cfg config.Config, options RunOptions) error writePlanLine(options.Stdout, plan, err) } if err != nil { - failures.add(pipeline.ID, destination.ID, displayBundlePath(sourceBundle.RootRelativePath), err) + failures.add(pipeline.ID, destination.ID, storage.DisplayPath(sourceBundle.RootRelativePath), err) summary.recordFailure() continue } summary.recordPlan(plan.Action) if !options.DryRun { if err := publish.Execute(ctx, req, plan); err != nil { - failures.add(pipeline.ID, destination.ID, displayBundlePath(sourceBundle.RootRelativePath), err) + failures.add(pipeline.ID, destination.ID, storage.DisplayPath(sourceBundle.RootRelativePath), err) summary.recordFailure() continue } if shouldNotify(plan.Action) { if err := notifier.Notify(ctx, notifyEvent(plan)); err != nil { - failures.add(pipeline.ID, destination.ID, displayBundlePath(sourceBundle.RootRelativePath), err) + failures.add(pipeline.ID, destination.ID, storage.DisplayPath(sourceBundle.RootRelativePath), err) summary.recordFailure() continue } @@ -138,17 +139,17 @@ func writePlanLine(w io.Writer, plan publish.Plan, planErr error) { if destinationID == "" { destinationID = "unknown" } - fmt.Fprintf(w, " - bundle=%s destination=%s action=error reason=%q\n", displayBundlePath(plan.BundlePath), destinationID, planErr.Error()) + fmt.Fprintf(w, " - bundle=%s destination=%s action=error reason=%q\n", storage.DisplayPath(plan.BundlePath), destinationID, planErr.Error()) return } - fmt.Fprintf(w, " - bundle=%s destination=%s action=%s outputs=%s reason=%q\n", displayBundlePath(plan.BundlePath), plan.DestinationID, plan.Action, outputSummary(plan.Outputs), plan.Reason) + fmt.Fprintf(w, " - bundle=%s destination=%s action=%s outputs=%s reason=%q\n", storage.DisplayPath(plan.BundlePath), plan.DestinationID, plan.Action, outputSummary(plan.Outputs), plan.Reason) } func writeErrorLine(w io.Writer, bundlePath, destinationID string, err error) { if w == nil { return } - fmt.Fprintf(w, " - bundle=%s destination=%s action=error reason=%q\n", displayBundlePath(bundlePath), destinationID, err.Error()) + fmt.Fprintf(w, " - bundle=%s destination=%s action=error reason=%q\n", storage.DisplayPath(bundlePath), destinationID, err.Error()) } func outputSummary(outputs []publish.Output) string { diff --git a/internal/bundle/discover.go b/internal/bundle/discover.go index 677beac..ab04885 100644 --- a/internal/bundle/discover.go +++ b/internal/bundle/discover.go @@ -35,7 +35,7 @@ func Discover(ctx context.Context, backend storage.Backend, sourceRoot string) ( } sort.Strings(roots) if len(roots) == 0 { - return nil, fmt.Errorf("no bundles found under %q", displayRoot(sourceRoot)) + return nil, fmt.Errorf("no bundles found under %q", storage.DisplayPath(sourceRoot)) } if err := rejectNestedRoots(roots); err != nil { return nil, err @@ -57,7 +57,7 @@ func rejectNestedRoots(roots []string) error { for index, root := range roots { for _, candidate := range roots[index+1:] { if isAncestor(root, candidate) { - return fmt.Errorf("nested manifest %q under bundle %q", displayRoot(candidate), displayRoot(root)) + return fmt.Errorf("nested manifest %q under bundle %q", storage.DisplayPath(candidate), storage.DisplayPath(root)) } } } diff --git a/internal/bundle/validate.go b/internal/bundle/validate.go index 8d6976a..2e1bc16 100644 --- a/internal/bundle/validate.go +++ b/internal/bundle/validate.go @@ -74,31 +74,31 @@ func validateAt(ctx context.Context, backend storage.Backend, bundleRoot, relati } manifest, err := ParseManifest(manifestData) if err != nil { - return Bundle{}, fmt.Errorf("bundle %q: %w", displayRoot(relativeRoot), err) + return Bundle{}, fmt.Errorf("bundle %q: %w", storage.DisplayPath(relativeRoot), err) } for index, manifestFile := range manifest.Files { filePath, err := storage.Join(bundleRoot, manifestFile.Path) if err != nil { - return Bundle{}, fmt.Errorf("bundle %q file %q: %w", displayRoot(relativeRoot), manifestFile.Path, err) + return Bundle{}, fmt.Errorf("bundle %q file %q: %w", storage.DisplayPath(relativeRoot), manifestFile.Path, err) } entry, err := backend.Stat(ctx, filePath) if err != nil { - return Bundle{}, fmt.Errorf("bundle %q file %q stat: %w", displayRoot(relativeRoot), manifestFile.Path, err) + return Bundle{}, fmt.Errorf("bundle %q file %q stat: %w", storage.DisplayPath(relativeRoot), manifestFile.Path, err) } if entry.Type != storage.EntryTypeFile { - return Bundle{}, fmt.Errorf("bundle %q file %q must be a regular file", displayRoot(relativeRoot), manifestFile.Path) + return Bundle{}, fmt.Errorf("bundle %q file %q must be a regular file", storage.DisplayPath(relativeRoot), manifestFile.Path) } if entry.Size != manifestFile.Size { - return Bundle{}, fmt.Errorf("bundle %q file %q size mismatch: got %d want %d", displayRoot(relativeRoot), manifestFile.Path, entry.Size, manifestFile.Size) + return Bundle{}, fmt.Errorf("bundle %q file %q size mismatch: got %d want %d", storage.DisplayPath(relativeRoot), manifestFile.Path, entry.Size, manifestFile.Size) } data, err := backend.ReadFile(ctx, filePath) if err != nil { - return Bundle{}, fmt.Errorf("bundle %q file %q read: %w", displayRoot(relativeRoot), manifestFile.Path, err) + return Bundle{}, fmt.Errorf("bundle %q file %q read: %w", storage.DisplayPath(relativeRoot), manifestFile.Path, err) } actualDigest := FileDigest(data) if actualDigest != manifestFile.SHA256 { - return Bundle{}, fmt.Errorf("bundle %q file %q sha256 mismatch: got %s want %s", displayRoot(relativeRoot), manifestFile.Path, actualDigest, manifestFile.SHA256) + return Bundle{}, fmt.Errorf("bundle %q file %q sha256 mismatch: got %s want %s", storage.DisplayPath(relativeRoot), manifestFile.Path, actualDigest, manifestFile.SHA256) } manifest.Files[index].SHA256 = actualDigest manifest.Files[index].Size = int64(len(data)) @@ -106,7 +106,7 @@ func validateAt(ctx context.Context, backend storage.Backend, bundleRoot, relati actualBundleDigest := BundleDigest(manifest.Files) if actualBundleDigest != manifest.Digest { - return Bundle{}, fmt.Errorf("bundle %q digest mismatch: got %s want %s", displayRoot(relativeRoot), actualBundleDigest, manifest.Digest) + return Bundle{}, fmt.Errorf("bundle %q digest mismatch: got %s want %s", storage.DisplayPath(relativeRoot), actualBundleDigest, manifest.Digest) } return Bundle{ @@ -114,10 +114,3 @@ func validateAt(ctx context.Context, backend storage.Backend, bundleRoot, relati Manifest: manifest, }, nil } - -func displayRoot(root string) string { - if root == "" { - return "." - } - return root -} diff --git a/internal/cli/root.go b/internal/cli/root.go index c020d4e..ac6adfd 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -2,7 +2,6 @@ package cli import ( "context" - "errors" "fmt" "io" "strings" @@ -67,10 +66,6 @@ func hasHelp(args []string) bool { } func fail(stderr io.Writer, err error) int { - if errors.Is(err, app.ErrNotImplemented) { - fmt.Fprintf(stderr, "%s: %s\n", app.Name, err) - return exitError - } fmt.Fprintf(stderr, "%s: %s\n", app.Name, err) return exitError } diff --git a/internal/publish/plan.go b/internal/publish/plan.go index d98bbdf..a7a5a63 100644 --- a/internal/publish/plan.go +++ b/internal/publish/plan.go @@ -139,10 +139,3 @@ func actionForComparison(comparison state.Comparison, transfer config.TransferPo return ActionFailConflict, "unsupported comparison outcome" } } - -func displayPath(path string) string { - if path == "" { - return "." - } - return path -} diff --git a/internal/publish/safety.go b/internal/publish/safety.go index a2cb9a4..56037fb 100644 --- a/internal/publish/safety.go +++ b/internal/publish/safety.go @@ -13,7 +13,7 @@ func ensureDestinationEmpty(ctx context.Context, backend storage.Backend, bundle return err } if hasAny { - return fmt.Errorf("destination bundle path %q is not empty after managed cleanup", displayPath(bundlePath)) + return fmt.Errorf("destination bundle path %q is not empty after managed cleanup", storage.DisplayPath(bundlePath)) } return nil } diff --git a/internal/storage/path.go b/internal/storage/path.go index 8f15980..496bb88 100644 --- a/internal/storage/path.go +++ b/internal/storage/path.go @@ -42,6 +42,13 @@ func StatePath(bundlePath string) (string, error) { return Join(bundlePath, StateFileName) } +func DisplayPath(path string) string { + if path == "" { + return "." + } + return path +} + func ManagedBundleTargets(bundlePath string, managedOutputPaths []string) ([]string, error) { if err := ValidatePrefix(bundlePath); err != nil { return nil, err diff --git a/internal/storage/path_test.go b/internal/storage/path_test.go index d8ccc22..dae0f11 100644 --- a/internal/storage/path_test.go +++ b/internal/storage/path_test.go @@ -67,6 +67,20 @@ func TestStatePath(t *testing.T) { } } +func TestDisplayPath(t *testing.T) { + tests := map[string]string{ + "": ".", + "bundle": "bundle", + } + for path, want := range tests { + t.Run(path, func(t *testing.T) { + if got := DisplayPath(path); got != want { + t.Fatalf("DisplayPath(%q) = %q, want %q", path, got, want) + } + }) + } +} + func TestManagedBundleTargets(t *testing.T) { tests := []struct { name string