clean empty staging directory
This commit is contained in:
@@ -122,7 +122,7 @@ func (f *FileSystem) Cleanup(ctx context.Context, ttl time.Duration) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := filepath.Walk(f.Staging, func(path string, info os.FileInfo, err error) error {
|
||||
err := filepath.Walk(f.Staging, func(fpath string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -131,8 +131,10 @@ func (f *FileSystem) Cleanup(ctx context.Context, ttl time.Duration) error {
|
||||
}
|
||||
age := time.Since(info.ModTime())
|
||||
if age > ttl {
|
||||
log.Printf("[INFO] remove staging image %s, age %v", path, age)
|
||||
return os.Remove(path)
|
||||
log.Printf("[INFO] remove staging image %s, age %v", fpath, age)
|
||||
rmErr := os.Remove(fpath)
|
||||
_ = os.Remove(path.Dir(fpath)) // try to remove directory
|
||||
return rmErr
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -268,6 +269,9 @@ func TestFsStore_Cleanup(t *testing.T) {
|
||||
|
||||
_, err = os.Stat(img1)
|
||||
assert.NotNil(t, err, "no file on staging anymore")
|
||||
_, err = os.Stat(path.Dir(img1))
|
||||
assert.NotNil(t, err, "no dir %s on staging anymore", path.Dir(img1))
|
||||
|
||||
_, err = os.Stat(img2)
|
||||
assert.NoError(t, err, "file on staging")
|
||||
_, err = os.Stat(img3)
|
||||
|
||||
Reference in New Issue
Block a user