diff --git a/orbit/changes/37340-tar.gz-update-bug-fix b/orbit/changes/37340-tar.gz-update-bug-fix new file mode 100644 index 0000000000..4c12d85a01 --- /dev/null +++ b/orbit/changes/37340-tar.gz-update-bug-fix @@ -0,0 +1 @@ +* Fixed bugs in auto-update of `.tar.gz` components ("Fleet Desktop" and osqueryd) in orbit. diff --git a/orbit/pkg/update/hash.go b/orbit/pkg/update/hash.go index 0865ac96e6..d612cc8a54 100644 --- a/orbit/pkg/update/hash.go +++ b/orbit/pkg/update/hash.go @@ -33,16 +33,21 @@ func fileHashes(meta *data.TargetFileMeta, localPath string) (metaHash []byte, l return nil, nil, err } - f, err := os.Open(localPath) - if err != nil { - // If tar.gz doesn't exist but a hash file does, use the cached hash file - if os.IsNotExist(err) && strings.HasSuffix(localPath, ".tar.gz") { - cachedHash, err := readCachedHash(localPath, meta) - if err == nil { - return metaHash, cachedHash, nil - } + // For .tar.gz components, try cached hash file first. + if strings.HasSuffix(localPath, ".tar.gz") { + cachedHash, err := readCachedHash(localPath, meta) + switch { + case err == nil: + return metaHash, cachedHash, nil + case os.IsNotExist(err): + // OK + default: log.Info().Err(err).Msg("failed to read cached hash file") } + } + + f, err := os.Open(localPath) + if err != nil { return nil, nil, fmt.Errorf("open file for hash: %w", err) } defer f.Close() diff --git a/orbit/pkg/update/update.go b/orbit/pkg/update/update.go index 0e89200fec..14c2373882 100644 --- a/orbit/pkg/update/update.go +++ b/orbit/pkg/update/update.go @@ -494,6 +494,9 @@ func (u *Updater) get(target string) (*LocalTarget, error) { return nil, fmt.Errorf("download %q: %w", repoPath, err) } removeCachedHashes(localTarget.Path) + if err := os.RemoveAll(localTarget.DirPath); err != nil { + return nil, fmt.Errorf("failed to remove old extracted dir: %q: %w", localTarget.DirPath, err) + } } else { // Hash matches! We can proceed without the tar.gz log.Debug().Str("path", localTarget.Path).Msg("using cached hash, tar.gz not needed")