Skip to content

Commit

Permalink
[TUF] Retry executable checks and directory renames on update download (
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored Jan 23, 2024
1 parent 33c6fd9 commit 4ee1d7d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions ee/tuf/library_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,24 @@ func (ulm *updateLibraryManager) moveVerifiedUpdate(binary autoupdatableBinary,
return fmt.Errorf("could not patch executable: %w", err)
}

// Validate the executable
if err := autoupdate.CheckExecutable(context.TODO(), executableLocation(stagedVersionedDirectory, binary), "--version"); err != nil {
return fmt.Errorf("could not verify executable: %w", err)
// Validate the executable -- the executable check will occasionally time out, especially on Windows,
// and we aren't in a rush here, so we retry a couple times.
if err := backoff.WaitFor(func() error {
return autoupdate.CheckExecutable(context.TODO(), executableLocation(stagedVersionedDirectory, binary), "--version")
}, 45*time.Second, 15*time.Second); err != nil {
return fmt.Errorf("could not verify executable after retries: %w", err)
}

// All good! Shelve it in the library under its version
// All good! Shelve it in the library under its version. We also perform some retries
// here for Windows, since sometimes Windows will think the binary is still in use and
// will refuse to move it.
newUpdateDirectory := filepath.Join(updatesDirectory(binary, ulm.baseDir), targetVersion)
if err := os.Rename(stagedVersionedDirectory, newUpdateDirectory); err != nil {
return fmt.Errorf("could not move staged target %s from %s to %s: %w", targetFilename, stagedVersionedDirectory, newUpdateDirectory, err)
if err := backoff.WaitFor(func() error {
return os.Rename(stagedVersionedDirectory, newUpdateDirectory)
}, 6*time.Second, 2*time.Second); err != nil {
return fmt.Errorf("could not move staged target %s from %s to %s after retries: %w", targetFilename, stagedVersionedDirectory, newUpdateDirectory, err)
}

// Need rwxr-xr-x so that the desktop (running as user) can execute the downloaded binary too
if err := os.Chmod(newUpdateDirectory, 0755); err != nil {
return fmt.Errorf("could not chmod %s: %w", newUpdateDirectory, err)
Expand Down

0 comments on commit 4ee1d7d

Please sign in to comment.