MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / replaceExecutable

Function replaceExecutable

cmd/update.go:168–185  ·  view source on GitHub ↗

replaceExecutable safely replaces the current executable with the new one

(currentPath, newPath string)

Source from the content-addressed store, hash-verified

166
167// replaceExecutable safely replaces the current executable with the new one
168func replaceExecutable(currentPath, newPath string) error {
169 // Rename current executable to .old (backup)
170 oldFile := currentPath + ".old"
171 if err := os.Rename(currentPath, oldFile); err != nil {
172 return fmt.Errorf("error backing up current version: %v", err)
173 }
174
175 // Move new executable into place
176 if err := os.Rename(newPath, currentPath); err != nil {
177 // Try to restore old version
178 os.Rename(oldFile, currentPath)
179 return fmt.Errorf("error installing new version: %v", err)
180 }
181
182 // Clean up old version
183 os.Remove(oldFile)
184 return nil
185}
186
187func getLatestRelease() (*GithubRelease, error) {
188 resp, err := http.Get("https://api.github.com/repos/cronitorio/cronitor-cli/releases/latest")

Callers 1

performUpdateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected