fix(lint): use ctx for debug logging in SelfUpdateBlockedReason
- commit
- 97129829edac011f9ecc086040c90df322544736
- author
- bnema · · 2025-12-30 21:44 UTC
- parent
- d23d7eb
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +7 -1
M internal/infrastructure/updater/applier.go +6 -0
| @@ -99,23 +99,29 @@ func (a *Applier) CanSelfUpdate(ctx context.Context) bool { | |||
| 99 | 99 | ||
| 100 | 100 | // SelfUpdateBlockedReason returns why self-update is blocked, or empty if allowed. | |
| 101 | 101 | func (a *Applier) SelfUpdateBlockedReason(ctx context.Context) port.SelfUpdateBlockedReason { | |
| 102 | + | log := logging.FromContext(ctx) | |
| 103 | + | ||
| 102 | 104 | // Flatpak sandboxed apps should not self-update; Flatpak handles updates. | |
| 103 | 105 | if env.IsFlatpak() { | |
| 106 | + | log.Debug().Msg("self-update blocked: running in Flatpak sandbox") | |
| 104 | 107 | return port.SelfUpdateBlockedFlatpak | |
| 105 | 108 | } | |
| 106 | 109 | ||
| 107 | 110 | // Pacman/AUR packages should not self-update; use pacman or AUR helper. | |
| 108 | 111 | if env.IsPacman() { | |
| 112 | + | log.Debug().Msg("self-update blocked: installed via pacman/AUR") | |
| 109 | 113 | return port.SelfUpdateBlockedPacman | |
| 110 | 114 | } | |
| 111 | 115 | ||
| 112 | 116 | binaryPath, err := a.GetBinaryPath() | |
| 113 | 117 | if err != nil { | |
| 118 | + | log.Debug().Err(err).Msg("self-update blocked: failed to get binary path") | |
| 114 | 119 | return port.SelfUpdateBlockedNotWritable | |
| 115 | 120 | } | |
| 116 | 121 | ||
| 117 | 122 | // Check if we have write permission on the binary file. | |
| 118 | 123 | if err := unix.Access(binaryPath, unix.W_OK); err != nil { | |
| 124 | + | log.Debug().Str("path", binaryPath).Err(err).Msg("self-update blocked: binary not writable") | |
| 119 | 125 | return port.SelfUpdateBlockedNotWritable | |
| 120 | 126 | } | |
| 121 | 127 | ||
| @@ -99,23 +99,29 @@ func (a *Applier) CanSelfUpdate(ctx context.Context) bool { | |||||
| 99 | 99 | ||||
| 100 | // SelfUpdateBlockedReason returns why self-update is blocked, or empty if allowed. | 100 | // SelfUpdateBlockedReason returns why self-update is blocked, or empty if allowed. | ||
| 101 | func (a *Applier) SelfUpdateBlockedReason(ctx context.Context) port.SelfUpdateBlockedReason { | 101 | func (a *Applier) SelfUpdateBlockedReason(ctx context.Context) port.SelfUpdateBlockedReason { | ||
| 102 | + | log := logging.FromContext(ctx) | |||
| 103 | + | ||||
| 102 | // Flatpak sandboxed apps should not self-update; Flatpak handles updates. | 104 | // Flatpak sandboxed apps should not self-update; Flatpak handles updates. | ||
| 103 | if env.IsFlatpak() { | 105 | if env.IsFlatpak() { | ||
| 106 | + | log.Debug().Msg("self-update blocked: running in Flatpak sandbox") | |||
| 104 | return port.SelfUpdateBlockedFlatpak | 107 | return port.SelfUpdateBlockedFlatpak | ||
| 105 | } | 108 | } | ||
| 106 | 109 | ||||
| 107 | // Pacman/AUR packages should not self-update; use pacman or AUR helper. | 110 | // Pacman/AUR packages should not self-update; use pacman or AUR helper. | ||
| 108 | if env.IsPacman() { | 111 | if env.IsPacman() { | ||
| 112 | + | log.Debug().Msg("self-update blocked: installed via pacman/AUR") | |||
| 109 | return port.SelfUpdateBlockedPacman | 113 | return port.SelfUpdateBlockedPacman | ||
| 110 | } | 114 | } | ||
| 111 | 115 | ||||
| 112 | binaryPath, err := a.GetBinaryPath() | 116 | binaryPath, err := a.GetBinaryPath() | ||
| 113 | if err != nil { | 117 | if err != nil { | ||
| 118 | + | log.Debug().Err(err).Msg("self-update blocked: failed to get binary path") | |||
| 114 | return port.SelfUpdateBlockedNotWritable | 119 | return port.SelfUpdateBlockedNotWritable | ||
| 115 | } | 120 | } | ||
| 116 | 121 | ||||
| 117 | // Check if we have write permission on the binary file. | 122 | // Check if we have write permission on the binary file. | ||
| 118 | if err := unix.Access(binaryPath, unix.W_OK); err != nil { | 123 | if err := unix.Access(binaryPath, unix.W_OK); err != nil { | ||
| 124 | + | log.Debug().Str("path", binaryPath).Err(err).Msg("self-update blocked: binary not writable") | |||
| 119 | return port.SelfUpdateBlockedNotWritable | 125 | return port.SelfUpdateBlockedNotWritable | ||
| 120 | } | 126 | } | ||
| 121 | 127 | ||||
M internal/infrastructure/updater/applier_test.go +1 -1
| @@ -170,6 +170,6 @@ func TestSelfUpdateBlockedReason_Constants(t *testing.T) { | |||
| 170 | 170 | } | |
| 171 | 171 | ||
| 172 | 172 | // Verify SelfUpdateAllowed is empty string | |
| 173 | - | assert.Equal(t, port.SelfUpdateBlockedReason(""), port.SelfUpdateAllowed, | |
| 173 | + | assert.Equal(t, port.SelfUpdateAllowed, port.SelfUpdateBlockedReason(""), | |
| 174 | 174 | "SelfUpdateAllowed should be empty string") | |
| 175 | 175 | } | |
| @@ -170,6 +170,6 @@ func TestSelfUpdateBlockedReason_Constants(t *testing.T) { | |||||
| 170 | } | 170 | } | ||
| 171 | 171 | ||||
| 172 | // Verify SelfUpdateAllowed is empty string | 172 | // Verify SelfUpdateAllowed is empty string | ||
| 173 | - | assert.Equal(t, port.SelfUpdateBlockedReason(""), port.SelfUpdateAllowed, | 173 | + | assert.Equal(t, port.SelfUpdateAllowed, port.SelfUpdateBlockedReason(""), |
| 174 | "SelfUpdateAllowed should be empty string") | 174 | "SelfUpdateAllowed should be empty string") | ||
| 175 | } | 175 | } | ||