Skip to content

Commit da51512

Browse files
authored
fix: cleanup the purge uploads as well when running the prune command (#138)
Signed-off-by: chlins <[email protected]>
1 parent baf6f13 commit da51512

File tree

6 files changed

+116
-3
lines changed

6 files changed

+116
-3
lines changed

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
run:
22
timeout: 3m
33
modules-download-mode: readonly
4+
skip-dirs:
5+
- test/mocks
46

57
linters-settings:
68
gocyclo:
@@ -17,8 +19,6 @@ issues:
1719
- linters:
1820
- staticcheck
1921
text: "SA1019:"
20-
exclude-dirs:
21-
- test/mocks
2222

2323
linters:
2424
disable-all: true

pkg/backend/prune.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ package backend
1818

1919
import (
2020
"context"
21+
"fmt"
2122
)
2223

2324
// Prune prunes the unused blobs and clean up the storage.
2425
func (b *backend) Prune(ctx context.Context, dryRun, removeUntagged bool) error {
25-
return b.store.PerformGC(ctx, dryRun, removeUntagged)
26+
if err := b.store.PerformGC(ctx, dryRun, removeUntagged); err != nil {
27+
return fmt.Errorf("faile to perform gc: %w", err)
28+
}
29+
30+
if err := b.store.PerformPurgeUploads(ctx, dryRun); err != nil {
31+
return fmt.Errorf("failed to perform purge uploads: %w", err)
32+
}
33+
34+
return nil
2635
}

pkg/storage/distribution/distribution.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"io"
2424
"regexp"
25+
"time"
2526

2627
distribution "github.com/distribution/distribution/v3"
2728
registry "github.com/distribution/distribution/v3/registry/storage"
@@ -315,3 +316,9 @@ func (s *storage) PerformGC(ctx context.Context, dryRun, removeUntagged bool) er
315316
RemoveUntagged: removeUntagged,
316317
})
317318
}
319+
320+
// PerformPurgeUploads performs the purge uploads in the storage to free up the space.
321+
func (s *storage) PerformPurgeUploads(ctx context.Context, dryRun bool) error {
322+
_, errs := registry.PurgeUploads(ctx, s.driver, time.Now(), !dryRun)
323+
return errors.Join(errs...)
324+
}

pkg/storage/storage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ type Storage interface {
5656
ListTags(ctx context.Context, repo string) ([]string, error)
5757
// PerformGC performs the garbage collection in the storage to free up the space.
5858
PerformGC(ctx context.Context, dryRun, removeUntagged bool) error
59+
// PerformPurgeUploads performs the purge uploads in the storage to free up the space.
60+
PerformPurgeUploads(ctx context.Context, dryRun bool) error
5961
}
6062

6163
// WithRootDir sets the root directory of the storage.

test/mocks/backend/backend.go

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/mocks/storage/storage.go

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)