From 51808b8bbe47c0ec342bca9417f6da72116f0c76 Mon Sep 17 00:00:00 2001 From: Brandon Duffany Date: Mon, 21 Oct 2024 10:29:44 -0700 Subject: [PATCH] filecache: restrict initial scan to group-specific dirs (#7757) The filecache has a `_tmp` dir which we should not scan, and we are also considering moving OCI + firecracker images to this cache directory, to prevent `executor.delete_build_root_on_startup` from wiping cached images. --- .../remote_execution/filecache/filecache.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/enterprise/server/remote_execution/filecache/filecache.go b/enterprise/server/remote_execution/filecache/filecache.go index 0f9eeb4ac99..898a6c62144 100644 --- a/enterprise/server/remote_execution/filecache/filecache.go +++ b/enterprise/server/remote_execution/filecache/filecache.go @@ -198,9 +198,26 @@ func (c *fileCache) scanDir() { } return nil } - if err := filepath.WalkDir(c.rootDir, walkFn); err != nil { + + entries, err := os.ReadDir(c.rootDir) + if err != nil && !os.IsNotExist(err) { log.Errorf("Error reading existing filecache dir: %q: %s", c.rootDir, err) } + for _, entry := range entries { + // Only scan the group-specific dirs (ignore _tmp and other dirs) + if entry.Name() != "ANON" && !strings.HasPrefix(entry.Name(), "GR") { + continue + } + if !entry.IsDir() { + continue + } + + groupDir := filepath.Join(c.rootDir, entry.Name()) + if err := filepath.WalkDir(groupDir, walkFn); err != nil { + log.Errorf("Error scanning filecache dir: %q: %s", groupDir, err) + } + } + c.lock.Lock() lruSize := c.l.Size() c.lock.Unlock()