1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-10 21:01:02 +02:00

Remove Temporary Files if the program terminates abnormal.

Fixes #799
This commit is contained in:
Zack 2024-09-03 09:28:42 -07:00
parent 149d7364fb
commit bb74eafd36
4 changed files with 61 additions and 26 deletions

11
main.go
View file

@ -5,12 +5,13 @@ package main
//go:generate git tag -af v$VERSION -m "v$VERSION"
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/schollz/croc/v10/src/cli"
"github.com/schollz/croc/v10/src/utils"
log "github.com/schollz/logger"
)
func main() {
@ -37,13 +38,17 @@ func main() {
go func() {
if err := cli.Run(); err != nil {
log.Fatalln(err)
log.Error(err)
}
// Exit the program gracefully
utils.RemoveMarkedFiles()
os.Exit(0)
}()
// Wait for a termination signal
sig := <-sigs
log.Println("Received signal:", sig)
log.Debugf("Received signal:", sig)
utils.RemoveMarkedFiles()
// Exit the program gracefully
os.Exit(0)