Skip to content

Commit

Permalink
[TUF] Retry temp directory removals (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored Jan 12, 2024
1 parent 6e46249 commit 65eb6b9
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions ee/tuf/library_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/Masterminds/semver"
"github.com/kolide/kit/fsutil"
"github.com/kolide/launcher/pkg/autoupdate"
"github.com/kolide/launcher/pkg/backoff"
"github.com/kolide/launcher/pkg/traces"
"github.com/theupdateframework/go-tuf/data"
tufutil "github.com/theupdateframework/go-tuf/util"
Expand Down Expand Up @@ -100,7 +101,9 @@ func (ulm *updateLibraryManager) AddToLibrary(binary autoupdatableBinary, curren
return
}
dirToRemove := filepath.Dir(stagedUpdatePath)
if err := os.RemoveAll(dirToRemove); err != nil {
if err := backoff.WaitFor(func() error {
return os.RemoveAll(dirToRemove)
}, 500*time.Millisecond, 100*time.Millisecond); err != nil {
ulm.slogger.Log(context.TODO(), slog.LevelWarn,
"could not remove temp staging directory",
"directory", dirToRemove,
Expand Down Expand Up @@ -187,13 +190,17 @@ func (ulm *updateLibraryManager) moveVerifiedUpdate(binary autoupdatableBinary,
return fmt.Errorf("could not create temporary directory for untarring and validating new update: %w", err)
}
defer func() {
// In case of error, clean up the staged version
if err := os.RemoveAll(stagedVersionedDirectory); err != nil {
ulm.slogger.Log(context.TODO(), slog.LevelWarn,
"could not remove staged update",
"directory", stagedVersionedDirectory,
"err", err,
)
// In case of error, clean up the staged version and its directory
if _, err := os.Stat(stagedVersionedDirectory); err == nil || !os.IsNotExist(err) {
if err := backoff.WaitFor(func() error {
return os.RemoveAll(stagedVersionedDirectory)
}, 500*time.Millisecond, 100*time.Millisecond); err != nil {
ulm.slogger.Log(context.TODO(), slog.LevelWarn,
"could not remove staged update",
"directory", stagedVersionedDirectory,
"err", err,
)
}
}
}()

Expand Down

0 comments on commit 65eb6b9

Please sign in to comment.