Skip to content

Commit

Permalink
Ensure TUF autoupdater finishes updates (when not performing download…
Browse files Browse the repository at this point in the history
…) quicker
  • Loading branch information
RebeccaMahany committed Aug 1, 2023
1 parent 7841f8c commit 7916e3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/autoupdate/tuf/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewTufAutoupdater(k types.Knapsack, metadataHttpClient *http.Client, mirror
checkInterval: k.AutoupdateInterval(),
store: k.AutoupdateErrorsStore(),
osquerier: osquerier,
osquerierRetryInterval: 1 * time.Minute,
osquerierRetryInterval: 30 * time.Second,
logger: log.NewNopLogger(),
}

Expand Down Expand Up @@ -184,10 +184,10 @@ func (ta *TufAutoupdater) Execute() (err error) {
}

func (ta *TufAutoupdater) Interrupt(_ error) {
ta.interrupt <- struct{}{}
if err := ta.libraryManager.Close(); err != nil {
level.Debug(ta.logger).Log("msg", "could not close library on interrupt", "err", err)
}
ta.interrupt <- struct{}{}
}

// tidyLibrary gets the current running version for each binary (so that the current version is not removed)
Expand Down Expand Up @@ -306,6 +306,10 @@ func (ta *TufAutoupdater) downloadUpdate(binary autoupdatableBinary, targets dat
return "", fmt.Errorf("could not find release: %w", err)
}

if ta.libraryManager.Available(binary, release) {
return "", nil
}

// Get the current running version if available -- don't error out if we can't
// get it, since the worst case is that we download an update whose version matches
// our install version.
Expand All @@ -315,10 +319,6 @@ func (ta *TufAutoupdater) downloadUpdate(binary autoupdatableBinary, targets dat
return "", nil
}

if ta.libraryManager.Available(binary, release) {
return "", nil
}

if err := ta.libraryManager.AddToLibrary(binary, currentVersion, release, releaseMetadata); err != nil {
return "", fmt.Errorf("could not add release %s for binary %s to library: %w", release, binary, err)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/autoupdate/tuf/library_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func newUpdateLibraryManager(mirrorUrl string, mirrorClient *http.Client, baseDi

// Close cleans up the temporary staging directory
func (ulm *updateLibraryManager) Close() error {
// Acquire lock to ensure we aren't interrupting an ongoing operation
for _, binary := range binaries {
ulm.lock.Lock(binary)
defer ulm.lock.Unlock(binary)
}

if err := os.RemoveAll(ulm.stagingDir); err != nil {
return fmt.Errorf("could not remove staging dir %s: %w", ulm.stagingDir, err)
}
Expand Down

0 comments on commit 7916e3f

Please sign in to comment.