16159: Merge branch 'master' into 16159-token-expiration-on-logout
[arvados.git] / services / keepstore / unix_volume.go
index 7af058ae57727123bc56ae135174fa3851748264..1706473cc892c43cbd5ad27751c49f43cbebc075 100644 (file)
@@ -304,6 +304,8 @@ func (v *UnixVolume) WriteBlock(ctx context.Context, loc string, rdr io.Reader)
        // avoid this by setting the output file's timestamps
        // explicitly, using a higher resolution clock.
        ts := time.Now()
+       v.os.stats.TickOps("utimes")
+       v.os.stats.Tick(&v.os.stats.UtimesOps)
        if err = os.Chtimes(tmpfile.Name(), ts, ts); err != nil {
                err = fmt.Errorf("error setting timestamps on %s: %s", tmpfile.Name(), err)
                v.os.Remove(tmpfile.Name())
@@ -697,10 +699,20 @@ func (v *UnixVolume) EmptyTrash() {
        err := filepath.Walk(v.Root, func(path string, info os.FileInfo, err error) error {
                if err != nil {
                        v.logger.WithError(err).Errorf("EmptyTrash: filepath.Walk(%q) failed", path)
+                       // Don't give up -- keep walking other
+                       // files/dirs
+                       return nil
+               } else if !info.Mode().IsDir() {
+                       todo <- dirent{path, info}
                        return nil
+               } else if path == v.Root || blockDirRe.MatchString(info.Name()) {
+                       // Descend into a directory that we might have
+                       // put trash in.
+                       return nil
+               } else {
+                       // Don't descend into other dirs.
+                       return filepath.SkipDir
                }
-               todo <- dirent{path, info}
-               return nil
        })
        close(todo)
        wg.Wait()