CLI: Cleanup temp files on exit

Fixes #135
master
lawl 3 years ago
parent 809f184e87
commit 077b4763fe

@ -39,15 +39,15 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
if opt.setcap {
err := makeBinarySetcapped()
if err != nil {
os.Exit(1)
cleanupExit(librnnoise, 1)
}
os.Exit(0)
cleanupExit(librnnoise, 0)
}
paClient, err := pulseaudio.NewClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Couldn't create pulseaudio client: %v\n", err)
os.Exit(1)
cleanupExit(librnnoise, 1)
}
defer paClient.Close()
@ -77,7 +77,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
fmt.Printf("\tDevice Name: %s\n\tDevice ID: %s\n\n", sinks[i].Name, sinks[i].ID)
}
os.Exit(0)
cleanupExit(librnnoise, 0)
}
if opt.threshold > 0 {
@ -93,9 +93,9 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
err := unloadSupressor(&ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error unloading PulseAudio Module: %+v\n", err)
os.Exit(1)
cleanupExit(librnnoise, 1)
}
os.Exit(0)
cleanupExit(librnnoise, 0)
}
if opt.loadInput {
@ -105,7 +105,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
defaultSource, err := getDefaultSourceID(paClient)
if err != nil {
fmt.Fprintf(os.Stderr, "No source specified to load and failed to load default source: %+v\n", err)
os.Exit(1)
cleanupExit(librnnoise, 1)
}
opt.sinkName = defaultSource
}
@ -115,13 +115,13 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
err := loadSupressor(&ctx, &sources[i], &device{})
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading PulseAudio Module: %+v\n", err)
os.Exit(1)
cleanupExit(librnnoise, 1)
}
os.Exit(0)
cleanupExit(librnnoise, 0)
}
}
fmt.Fprintf(os.Stderr, "PulseAudio source not found: %s\n", opt.sinkName)
os.Exit(1)
cleanupExit(librnnoise, 1)
}
if opt.loadOutput {
@ -131,7 +131,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
defaultSink, err := getDefaultSinkID(paClient)
if err != nil {
fmt.Fprintf(os.Stderr, "No sink specified to load and failed to load default sink: %+v\n", err)
os.Exit(1)
cleanupExit(librnnoise, 1)
}
opt.sinkName = defaultSink
}
@ -141,13 +141,18 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
err := loadSupressor(&ctx, &device{}, &sinks[i])
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading PulseAudio Module: %+v\n", err)
os.Exit(1)
cleanupExit(librnnoise, 1)
}
os.Exit(0)
cleanupExit(librnnoise, 0)
}
}
fmt.Fprintf(os.Stderr, "PulseAudio sink not found: %s\n", opt.sinkName)
os.Exit(1)
cleanupExit(librnnoise, 1)
}
}
func cleanupExit(librnnoise string, exitCode int) {
removeLib(librnnoise)
os.Exit(exitCode)
}

Loading…
Cancel
Save