Skip to content

Commit afaa1f4

Browse files
nervghalexey-igrychev
authored andcommitted
fix(host-cleanup): use signal err for tmp cleaning
Signed-off-by: Alexandr Zaytsev <alexandr.zaytsev@flant.com>
1 parent e4e7851 commit afaa1f4

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

pkg/host_cleaning/host_cleanup.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ func RunAutoHostCleanup(ctx context.Context, backend container_backend.Container
9999

100100
func RunHostCleanup(ctx context.Context, backend container_backend.ContainerBackend, options HostCleanupOptions) error {
101101
if err := logboek.Context(ctx).LogProcess("Running GC for tmp data").DoError(func() error {
102-
if err := tmp_manager.RunGC(ctx, options.DryRun); err != nil {
102+
if err := tmp_manager.RunGC(ctx, options.DryRun); errors.Is(err, tmp_manager.ErrPathRemoval) {
103+
return nil
104+
} else if err != nil {
103105
return fmt.Errorf("tmp files GC failed: %w", err)
104106
}
105107
return nil

pkg/tmp_manager/gc.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ const (
1717
minFileAge = 2 * time.Hour
1818
)
1919

20-
var timeSince = time.Since // for stubbing in tests
20+
var (
21+
ErrPathRemoval = errors.New("path removal")
22+
23+
timeSince = time.Since // for stubbing in tests
24+
)
2125

2226
func ShouldRunAutoGC() (bool, error) {
2327
projectDirsToRemove, pathsToRemove, err := collectPaths()
@@ -47,7 +51,7 @@ func runGCForPaths(ctx context.Context, dryRun bool, paths []string) error {
4751
}
4852

4953
if err := os.RemoveAll(path); err != nil {
50-
removeErrors = append(removeErrors, fmt.Errorf("unable to remove path %s: %w", path, err))
54+
removeErrors = append(removeErrors, errors.Join(ErrPathRemoval, err))
5155
}
5256
}
5357

0 commit comments

Comments
 (0)