Terminal: Monitored hashes cleanup

This commit is contained in:
Kleissner
2022-01-12 23:57:14 +01:00
parent 1a8f4cc7d6
commit 58cb870116

View File

@@ -54,6 +54,13 @@ func showHelp(output io.Writer) {
func userCommands(backend *core.Backend, input io.Reader, output io.Writer, terminateSignal chan struct{}) {
reader := bufio.NewReader(input)
monitoredHashes := make(map[string]struct{})
defer func() { // unmonitor hashes in case of terminate signal
for hash := range monitoredHashes {
hashMonitorControl([]byte(hash), 1)
}
}()
fmt.Fprint(output, appName+" "+core.Version+"\n------------------------------\n")
showHelp(output)
@@ -361,8 +368,10 @@ func userCommands(backend *core.Backend, input io.Reader, output io.Writer, term
added := hashMonitorControl(hash, 2)
if added {
monitoredHashes[string(hash)] = struct{}{}
fmt.Fprintf(output, "The hash was added to the monitoring list.\n")
} else {
delete(monitoredHashes, string(hash))
fmt.Fprintf(output, "The hash was removed from the monitoring list.\n")
}