-
Notifications
You must be signed in to change notification settings - Fork 255
/
cleanup.go
36 lines (32 loc) · 879 Bytes
/
cleanup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package plugin
import (
"context"
"log"
"os"
"time"
"github.com/turbot/go-kit/files"
"github.com/turbot/steampipe/pkg/filepaths"
)
func CleanupOldTmpDirs(ctx context.Context) {
const tmpDirAgeThreshold = 24 * time.Hour
tmpDirs, err := files.ListFilesWithContext(ctx, filepaths.EnsurePluginDir(), &files.ListOptions{
Include: []string{"tmp-*"},
Flags: files.DirectoriesRecursive,
})
if err != nil {
log.Printf("[TRACE] Error while globbing for tmp dirs in plugin dir: %s", err)
return
}
for _, tmpDir := range tmpDirs {
stat, err := os.Stat(tmpDir)
if err != nil {
log.Printf("[TRACE] Error while stating tmp dir %s: %s", tmpDir, err)
continue
}
if time.Since(stat.ModTime()) > tmpDirAgeThreshold {
if err := os.RemoveAll(tmpDir); err != nil {
log.Printf("[TRACE] Error while removing old tmp dir %s: %s", tmpDir, err)
}
}
}
}