Remove stale cleanup leftovers

This commit is contained in:
2026-05-31 03:41:56 +00:00
parent 9782981fb2
commit 9d1ded301e
11 changed files with 42 additions and 54 deletions

View File

@@ -1,14 +1,10 @@
package app
import "errors"
const Name = "distributor"
// Version can be replaced at build time with -ldflags "-X .../internal/app.Version=<value>".
var Version = "dev"
var ErrNotImplemented = errors.New("not implemented")
func VersionString() string {
return Name + " " + Version
}

View File

@@ -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
}

View File

@@ -1,5 +0,0 @@
package app
type Pipeline struct {
ID string
}

View File

@@ -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 {

View File

@@ -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))
}
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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