mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-03-25 23:30:41 +01:00
cmd/cli: make --cleanup removing more files
While at it, also implementing self-delete function for Windows.
This commit is contained in:
committed by
Cuong Manh Le
parent
72bf80533e
commit
04947b4d87
@@ -48,6 +48,7 @@ import (
|
||||
|
||||
// selfCheckInternalTestDomain is used for testing ctrld self response to clients.
|
||||
const selfCheckInternalTestDomain = "ctrld" + loopTestDomain
|
||||
const windowsForwardersFilename = ".forwarders.txt"
|
||||
|
||||
var (
|
||||
version = "dev"
|
||||
@@ -610,8 +611,22 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`,
|
||||
files = append(files, filepath.Join(dir, ctrldControlUnixSock))
|
||||
files = append(files, filepath.Join(dir, ctrldLogUnixSock))
|
||||
}
|
||||
// Static DNS settings files.
|
||||
withEachPhysicalInterfaces("", "", func(i *net.Interface) error {
|
||||
file := savedStaticDnsSettingsFilePath(i)
|
||||
if _, err := os.Stat(file); err == nil {
|
||||
files = append(files, file)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// Windows forwarders file.
|
||||
if windowsHasLocalDnsServerRunning() {
|
||||
files = append(files, absHomeDir(windowsForwardersFilename))
|
||||
}
|
||||
// Binary itself.
|
||||
if bin, _ := os.Executable(); bin != "" {
|
||||
|
||||
bin, _ := os.Executable()
|
||||
if bin != "" && supportedSelfDelete {
|
||||
files = append(files, bin)
|
||||
}
|
||||
for _, file := range files {
|
||||
@@ -627,6 +642,13 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`,
|
||||
mainLog.Load().Debug().Msgf("file removed: %s", file)
|
||||
}
|
||||
}
|
||||
if err := selfDeleteExe(); err != nil {
|
||||
mainLog.Load().Warn().Err(err).Msg("failed to remove file")
|
||||
} else {
|
||||
if !supportedSelfDelete {
|
||||
mainLog.Load().Debug().Msgf("file removed: %s", bin)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user