mirror of
https://github.com/turbot/steampipe.git
synced 2026-02-16 16:00:11 -05:00
37 lines
879 B
Go
37 lines
879 B
Go
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)
|
|
}
|
|
}
|
|
}
|
|
}
|