diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-08-15 17:14:32 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-08-15 17:18:08 +0300 |
commit | 0fcb9549c792532bd7e987f8682ae58fb7c389b7 (patch) | |
tree | 72ebc8877673aad73aa9cdc82d1c2aec3c233bf9 | |
parent | e091fb7fe40d97c7eecba9d9dded027393261e7e (diff) |
Check if dir exists before cleaning its content
The cleanWalk didn't check if the directory actually existed. That
created an error message, while it really isn't an error. This change
checks if the error is just telling us the dir isn't present.
Noted in: https://gitlab.com/gitlab-org/gitaly/merge_requests/1366#note_204037125
-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 |