updater.go RawHistoryFolder
1// Package port defines interfaces for external dependencies.
2package port
3
4import (
5 "context"
6 "errors"
7
8 "github.com/bnema/dumber/internal/domain/entity"
9)
10
11// ErrUpdateCheckTransient indicates a temporary update-check failure that should not be treated as actionable.
12var ErrUpdateCheckTransient = errors.New("transient update check failure")
13
14// UpdateChecker checks for available updates from a remote source.
15type UpdateChecker interface {
16 // CheckForUpdate compares the current version with the latest available release.
17 // Returns update info including whether a newer version is available.
18 CheckForUpdate(ctx context.Context, currentVersion string) (*entity.UpdateInfo, error)
19}
20
21// UpdateDownloader downloads and extracts update archives.
22type UpdateDownloader interface {
23 // Download fetches the update archive to the specified destination directory.
24 // Returns the path to the downloaded archive file.
25 Download(ctx context.Context, downloadURL string, destDir string) (archivePath string, err error)
26
27 // Extract extracts the binary from the downloaded archive.
28 // Returns the path to the extracted binary.
29 Extract(ctx context.Context, archivePath string, destDir string) (binaryPath string, err error)
30}
31
32// SelfUpdateBlockedReason indicates why self-update is not available.
33type SelfUpdateBlockedReason string
34
35const (
36 // SelfUpdateAllowed means self-update is possible.
37 SelfUpdateAllowed SelfUpdateBlockedReason = ""
38 // SelfUpdateBlockedFlatpak means updates are managed by Flatpak.
39 SelfUpdateBlockedFlatpak SelfUpdateBlockedReason = "flatpak"
40 // SelfUpdateBlockedPacman means updates are managed by pacman/AUR.
41 SelfUpdateBlockedPacman SelfUpdateBlockedReason = "pacman"
42 // SelfUpdateBlockedNotWritable means the binary is not writable.
43 SelfUpdateBlockedNotWritable SelfUpdateBlockedReason = "not_writable"
44)
45
46// UpdateApplier stages and applies updates.
47type UpdateApplier interface {
48 // CanSelfUpdate checks if the current binary is writable by the current user.
49 // Returns true if auto-update is possible, false if user lacks write permission.
50 CanSelfUpdate(ctx context.Context) bool
51
52 // SelfUpdateBlockedReason returns why self-update is blocked, or empty if allowed.
53 SelfUpdateBlockedReason(ctx context.Context) SelfUpdateBlockedReason
54
55 // GetBinaryPath returns the path to the currently running binary.
56 GetBinaryPath() (string, error)
57
58 // StageUpdate prepares the new binary to be applied on exit.
59 // The staged update will be applied when ApplyOnExit is called.
60 StageUpdate(ctx context.Context, newBinaryPath string) error
61
62 // HasStagedUpdate checks if there is an update staged and ready to apply.
63 HasStagedUpdate(ctx context.Context) bool
64
65 // ApplyOnExit replaces the current binary with the staged update.
66 // This should be called during graceful shutdown.
67 // Returns the path to the backup of the old binary.
68 ApplyOnExit(ctx context.Context) (backupPath string, err error)
69
70 // ClearStagedUpdate removes any staged update without applying it.
71 ClearStagedUpdate(ctx context.Context) error
72}