mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
orbit: Always update orbit symlink when changing channels (#9188)
This commit is contained in:
parent
08aafe821e
commit
152a1b792e
2 changed files with 35 additions and 1 deletions
2
orbit/changes/bug-9053-update-symlink-on-change
Normal file
2
orbit/changes/bug-9053-update-symlink-on-change
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
* Orbit now restarts and switches channels when needed,
|
||||
even if the new channel is already installed
|
||||
|
|
@ -138,9 +138,20 @@ func (r *Runner) UpdateAction() (bool, error) {
|
|||
if err != nil {
|
||||
return didUpdate, fmt.Errorf("select hash for cache: %w", err)
|
||||
}
|
||||
|
||||
// Check if we need to update the orbit symlink (e.g. if channel changed)
|
||||
needsSymlinkUpdate := false
|
||||
if target == "orbit" {
|
||||
var err error
|
||||
needsSymlinkUpdate, err = r.needsOrbitSymlinkUpdate()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("check symlink failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the hash of the repository is different than
|
||||
// that of the target local file.
|
||||
if !bytes.Equal(r.localHashes[target], metaHash) {
|
||||
if !bytes.Equal(r.localHashes[target], metaHash) || needsSymlinkUpdate {
|
||||
// Update detected
|
||||
log.Info().Str("target", target).Msg("update detected")
|
||||
if err := r.updateTarget(target); err != nil {
|
||||
|
|
@ -156,6 +167,27 @@ func (r *Runner) UpdateAction() (bool, error) {
|
|||
return didUpdate, nil
|
||||
}
|
||||
|
||||
func (r *Runner) needsOrbitSymlinkUpdate() (bool, error) {
|
||||
localTarget, err := r.updater.Get("orbit")
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("get binary: %w", err)
|
||||
}
|
||||
path := localTarget.ExecPath
|
||||
|
||||
// Symlink Orbit binary
|
||||
linkPath := filepath.Join(r.updater.opt.RootDirectory, "bin", "orbit", filepath.Base(path))
|
||||
|
||||
existingPath, err := os.Readlink(linkPath)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return true, nil
|
||||
}
|
||||
return false, fmt.Errorf("read existing symlink: %w", err)
|
||||
}
|
||||
|
||||
return existingPath != path, nil
|
||||
}
|
||||
|
||||
func (r *Runner) updateTarget(target string) error {
|
||||
localTarget, err := r.updater.Get(target)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue