Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

// UpgradeConfirmCB is a function that is called when an update is ready to be applied.
type UpgradeConfirmCB func(current, target releaser.Version) bool
type CleanupCB func() error

var DefaultUpgradeConfirmCb = func(current, target releaser.Version) bool { return true }

Expand All @@ -32,7 +33,7 @@ var DefaultUpgradeConfirmCb = func(current, target releaser.Version) bool { retu
// If an update is applied, it will restart the application with the new version.
// If no update is available, it will return nil.
// If an error occurs during the update process, it will return the error.
func CheckForUpdates(targetPath string, current releaser.Version, client *releaser.Client, upgradeCb UpgradeConfirmCB) error {
func CheckForUpdates(targetPath string, current releaser.Version, client *releaser.Client, upgradeCb UpgradeConfirmCB, cleanup CleanupCB) error {
restartPath, err := apply(targetPath, current, client, upgradeCb)
if err != nil {
return err
Expand All @@ -45,7 +46,12 @@ func CheckForUpdates(targetPath string, current releaser.Version, client *releas
if err := execApp(restartPath); err != nil {
return fmt.Errorf("update applied, but failed to restart application: %w", err)
}
// TODO: allow to define custom "exit"

if cleanup != nil {
if err := cleanup(); err != nil {
return fmt.Errorf("cleanup failed: %w", err)
}
}
Comment on lines +50 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be clever here. A long cleanup procedure could interfere with the execApp above. If the app is set to have only one instance, the exec above will fail because the app will run the cleanup while the new one starts. I would say that at least the cleanup should be done before the execApp. But I am wondering if the caller should also run its exit code. Run our self os.Exit is risky because it will prevent the caller from running the deferred functions, so maybe something will not be correctly cleaned.

os.Exit(0)
return nil
}
Loading