[ARVADOS] created: 1.3.0-2656-gb257b5e4f

Git user git at public.arvados.org
Fri Jun 12 20:24:59 UTC 2020


        at  b257b5e4fca36172a79db2fd2cf8ab843cf50d1c (commit)


commit b257b5e4fca36172a79db2fd2cf8ab843cf50d1c
Author: Tom Clegg <tom at tomclegg.ca>
Date:   Fri Jun 12 16:14:20 2020 -0400

    16425: Don't scan dirs that we don't write in.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at tomclegg.ca>

diff --git a/services/keepstore/unix_volume.go b/services/keepstore/unix_volume.go
index 5026e2d32..1706473cc 100644
--- a/services/keepstore/unix_volume.go
+++ b/services/keepstore/unix_volume.go
@@ -699,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()
diff --git a/services/keepstore/unix_volume_test.go b/services/keepstore/unix_volume_test.go
index 5a3a53694..6b42dbc51 100644
--- a/services/keepstore/unix_volume_test.go
+++ b/services/keepstore/unix_volume_test.go
@@ -424,3 +424,26 @@ func (s *UnixVolumeSuite) TestStats(c *check.C) {
 	c.Check(err, check.IsNil)
 	c.Check(stats(), check.Matches, `.*"FlockOps":2,.*`)
 }
+
+func (s *UnixVolumeSuite) TestSkipUnusedDirs(c *check.C) {
+	vol := s.newTestableUnixVolume(c, s.cluster, arvados.Volume{Replication: 1}, s.metrics, false)
+
+	err := os.Mkdir(vol.UnixVolume.Root+"/aaa", 0777)
+	c.Assert(err, check.IsNil)
+	err = os.Mkdir(vol.UnixVolume.Root+"/.aaa", 0777) // EmptyTrash should not look here
+	c.Assert(err, check.IsNil)
+	deleteme := vol.UnixVolume.Root + "/aaa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.trash.1"
+	err = ioutil.WriteFile(deleteme, []byte{1, 2, 3}, 0777)
+	c.Assert(err, check.IsNil)
+	skipme := vol.UnixVolume.Root + "/.aaa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.trash.1"
+	err = ioutil.WriteFile(skipme, []byte{1, 2, 3}, 0777)
+	c.Assert(err, check.IsNil)
+	vol.EmptyTrash()
+
+	_, err = os.Stat(skipme)
+	c.Check(err, check.IsNil)
+
+	_, err = os.Stat(deleteme)
+	c.Check(err, check.NotNil)
+	c.Check(os.IsNotExist(err), check.Equals, true)
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list