Skip to content
Merged
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
16 changes: 10 additions & 6 deletions commands/daemon.install.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@ func commandDaemonInstall(c *cli.Context) error {
color.Green.Printf("✅ Found daemon binary at: %s\n", daemonBinPath)
}

// If we picked a system-managed binary but a stale curl-installer copy
// still lives under ~/.shelltime/bin, remove it so future resolution
// stays unambiguous.
// If we picked a system-managed binary but a curl-installer copy still
// lives under ~/.shelltime/bin, rename it to shelltime-daemon.bak rather
// than delete it. Future resolution stays unambiguous AND the .bak
// recovery branch above can restore it on the next `daemon install` —
// no GitHub re-download when the user later clears the system binary.
curlDaemonPath := model.GetCurlInstallerDaemonPath()
if daemonBinPath != curlDaemonPath {
if info, statErr := os.Stat(curlDaemonPath); statErr == nil && !info.IsDir() {
if rmErr := os.Remove(curlDaemonPath); rmErr == nil {
color.Yellow.Printf("🧹 Removed stale curl-installer daemon at %s\n", curlDaemonPath)
preservedPath := curlDaemonPath + ".bak"
_ = os.Remove(preservedPath)
if rnErr := os.Rename(curlDaemonPath, preservedPath); rnErr == nil {
Comment on lines +73 to +74
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

On Unix-like systems (Linux and macOS), os.Rename atomically replaces the destination file if it already exists. The explicit os.Remove(preservedPath) is redundant and introduces a small non-atomic window where the backup file is missing. While harmless in this context, relying on os.Rename's native behavior is more idiomatic and robust.

if rnErr := os.Rename(curlDaemonPath, preservedPath); rnErr == nil {

color.Yellow.Printf("📦 Preserved curl-installer daemon as %s (auto-restores on next `daemon install`).\n", preservedPath)
} else {
color.Yellow.Printf("⚠️ Could not remove stale daemon at %s: %v\n", curlDaemonPath, rmErr)
color.Yellow.Printf("⚠️ Could not preserve curl-installer daemon at %s: %v\n", curlDaemonPath, rnErr)
}
}
}
Expand Down
Loading