diff options
author | John Cai <jcai@gitlab.com> | 2019-08-16 03:49:21 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-08-16 03:49:21 +0300 |
commit | faff8ec9f91a09d042ea3dd47421cc09f9219d6a (patch) | |
tree | e318a0ec683fdf82d6eeae751d1c8300ca201764 | |
parent | ae0b29bacf06026b0cb98878d869d6d2c3708b02 (diff) | |
parent | 0fcb9549c792532bd7e987f8682ae58fb7c389b7 (diff) |
Merge branch 'zj-cleanwalk-dir-non-existing' into 'master'
Check if dir exists before cleaning its content
Closes #1864
See merge request gitlab-org/gitaly!1431
-rw-r--r-- | internal/cache/walk_test.go | 12 | ||||
-rw-r--r-- | internal/cache/walker.go | 8 |
2 files changed, 19 insertions, 1 deletions
diff --git a/internal/cache/walk_test.go b/internal/cache/walk_test.go new file mode 100644 index 000000000..bfe037ff4 --- /dev/null +++ b/internal/cache/walk_test.go @@ -0,0 +1,12 @@ +package cache + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestcleanWalkDirNotExists(t *testing.T) { + err := cleanWalk("/path/that/does/not/exist") + assert.NoError(t, err, "cleanWalk returned an error for a non existing directory") +} diff --git a/internal/cache/walker.go b/internal/cache/walker.go index a782ebd6b..4bbff532d 100644 --- a/internal/cache/walker.go +++ b/internal/cache/walker.go @@ -18,7 +18,7 @@ import ( func cleanWalk(storagePath string) error { cachePath := filepath.Join(storagePath, tempdir.CachePrefix) - return filepath.Walk(cachePath, func(path string, info os.FileInfo, err error) error { + err := filepath.Walk(cachePath, func(path string, info os.FileInfo, err error) error { if err != nil { return err } @@ -47,6 +47,12 @@ func cleanWalk(storagePath string) error { return nil }) + + if os.IsNotExist(err) { + return nil + } + + return err } const cleanWalkFrequency = 10 * time.Minute |