filecache: Ignore "does not exist" errors in prune
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 12 Sep 2019 15:24:34 +0000 (17:24 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 12 Sep 2019 15:37:41 +0000 (17:37 +0200)
Fixes #6326
Fixes #5745

cache/filecache/filecache_pruner.go

index c6fd4497e4ca23fa89b8cab3dc5d2af60e54d21d..7f68c8b822f4155ddea0de5487b88d8d4ddee230 100644 (file)
@@ -31,12 +31,15 @@ func (c Caches) Prune() (int, error) {
 
                count, err := cache.Prune(false)
 
+               counter += count
+
                if err != nil {
+                       if os.IsNotExist(err) {
+                               continue
+                       }
                        return counter, errors.Wrapf(err, "failed to prune cache %q", k)
                }
 
-               counter += count
-
        }
 
        return counter, nil
@@ -68,7 +71,11 @@ func (c *Cache) Prune(force bool) (int, error) {
                        _, err = f.Readdirnames(1)
                        if err == io.EOF {
                                // Empty dir.
-                               return c.Fs.Remove(name)
+                               err = c.Fs.Remove(name)
+                       }
+
+                       if err != nil && !os.IsNotExist(err) {
+                               return err
                        }
 
                        return nil
@@ -87,7 +94,11 @@ func (c *Cache) Prune(force bool) (int, error) {
                        if err == nil {
                                counter++
                        }
-                       return err
+
+                       if err != nil && !os.IsNotExist(err) {
+                               return err
+                       }
+
                }
 
                return nil