From 8b4d86237236df2de63107baeeaecc1cba7eff44 Mon Sep 17 00:00:00 2001 From: Viktor Kuzmin Date: Tue, 6 Sep 2022 20:11:30 +0300 Subject: Cleanup cache directories --- pkg/driver/utils.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'pkg/driver/utils.go') diff --git a/pkg/driver/utils.go b/pkg/driver/utils.go index 485d4da..b629543 100644 --- a/pkg/driver/utils.go +++ b/pkg/driver/utils.go @@ -3,6 +3,7 @@ package driver import ( "fmt" "os" + "path/filepath" "strings" "sync" @@ -14,6 +15,10 @@ import ( ) func NewNodeServer(n *SeaweedFsDriver) *NodeServer { + if err := removeDirContent(n.CacheDir); err != nil { + glog.Warning("error cleaning up cache dir") + } + return &NodeServer{ Driver: n, volumeMutexes: NewKeyMutex(), @@ -83,6 +88,22 @@ func checkMount(targetPath string) (bool, error) { return notMnt, nil } +func removeDirContent(path string) error { + files, err := filepath.Glob(filepath.Join(path, "*")) + if err != nil { + return err + } + + for _, file := range files { + err = os.RemoveAll(file) + if err != nil { + return err + } + } + + return nil +} + type KeyMutex struct { mutexes sync.Map } -- cgit v1.2.3