mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
fix: complete porting of initUninstallCmd logic to ServiceCommand.Uninstall
Add missing selfDeleteExe() call and supportedSelfDelete check that were present in the original initUninstallCmd function. This ensures the uninstall command properly handles self-deletion of the binary when cleanup is enabled. The original logic included: - selfDeleteExe() call for self-deletion - supportedSelfDelete check for platform-specific behavior - Proper error handling and logging This completes the porting of all functionality from the original initUninstallCmd to the new ServiceCommand.Uninstall method.
This commit is contained in:
committed by
Cuong Manh Le
parent
13de41d854
commit
9f656269ac
@@ -551,6 +551,18 @@ func (sc *ServiceCommand) Uninstall(cmd *cobra.Command, args []string) error {
|
||||
files = append(files, file)
|
||||
return nil
|
||||
})
|
||||
bin, err := os.Executable()
|
||||
if err != nil {
|
||||
mainLog.Load().Warn().Err(err).Msg("failed to get executable path")
|
||||
}
|
||||
if bin != "" && supportedSelfDelete {
|
||||
files = append(files, bin)
|
||||
}
|
||||
// Backup file after upgrading.
|
||||
oldBin := bin + oldBinSuffix
|
||||
if _, err := os.Stat(oldBin); err == nil {
|
||||
files = append(files, oldBin)
|
||||
}
|
||||
for _, file := range files {
|
||||
if file == "" {
|
||||
continue
|
||||
@@ -559,6 +571,14 @@ func (sc *ServiceCommand) Uninstall(cmd *cobra.Command, args []string) error {
|
||||
mainLog.Load().Notice().Msgf("removed %s", file)
|
||||
}
|
||||
}
|
||||
// Self-delete the ctrld binary if supported
|
||||
if err := selfDeleteExe(); err != nil {
|
||||
mainLog.Load().Warn().Err(err).Msg("failed to delete ctrld binary")
|
||||
} else {
|
||||
if !supportedSelfDelete {
|
||||
mainLog.Load().Debug().Msgf("file removed: %s", bin)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user