Cleanup old temp files on startup

This commit is contained in:
Samuel Lorch 2024-07-06 03:05:58 +02:00
parent e8f7521fa4
commit b99a818040
3 changed files with 18 additions and 3 deletions

View file

@ -5,6 +5,7 @@ import (
"io"
"log/slog"
"net/http"
"path/filepath"
"git.lastassault.de/speatzle/morffix/rpc"
@ -36,6 +37,20 @@ func Start(_conf config.Config) {
return
}
slog.InfoContext(ctx, "Cleaning tmp Files...")
files, err := filepath.Glob("/tmp/morffix-*")
if err != nil {
slog.Error("Get tmp Files", "err", err)
return
}
for _, f := range files {
slog.InfoContext(ctx, "Deleting File", "path", f)
if err := os.Remove(f); err != nil {
slog.Error("Deleting tmp File", "err", err, "path", f)
return
}
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt)
exit := false