From 278e017af69f3141ee74bf94bcffb0698a98c9d9 Mon Sep 17 00:00:00 2001 From: matthew-pilot Date: Thu, 28 May 2026 04:30:07 +0000 Subject: [PATCH] =?UTF-8?q?fix(dataexchange):=20rename=20cap=E2=86=92maxFi?= =?UTF-8?q?les=20to=20unshadow=20Go=20builtin=20(PILOT-185)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The local variable 'cap' in evictInboxOverflow shadows the Go builtin cap(). Rename to maxFiles to remove the footgun. Closes: PILOT-185 --- service.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/service.go b/service.go index f669950..cd88804 100644 --- a/service.go +++ b/service.go @@ -295,16 +295,16 @@ func (s *Service) saveInboxMessage(frame *Frame, from protocol.Addr) error { // logged and the loop continues. Called periodically from // saveInboxMessage. func (s *Service) evictInboxOverflow(dir string) { - cap := s.cfg.InboxMaxFiles - if cap <= 0 { - cap = 10000 + maxFiles := s.cfg.InboxMaxFiles + if maxFiles <= 0 { + maxFiles = 10000 } entries, err := os.ReadDir(dir) if err != nil { slog.Debug("inbox evict: readdir", "dir", dir, "err", err) return } - if len(entries) <= cap { + if len(entries) <= maxFiles { return } type aged struct { @@ -322,14 +322,14 @@ func (s *Service) evictInboxOverflow(dir string) { } files = append(files, aged{name: e.Name(), mod: info.ModTime()}) } - if len(files) <= cap { + if len(files) <= maxFiles { return } // Oldest first. sort.Slice(files, func(i, j int) bool { return files[i].mod.Before(files[j].mod) }) - toEvict := len(files) - cap + toEvict := len(files) - maxFiles for i := 0; i < toEvict; i++ { _ = os.Remove(filepath.Join(dir, files[i].name)) } - slog.Info("inbox eviction", "dir", dir, "evicted", toEvict, "remaining", cap) + slog.Info("inbox eviction", "dir", dir, "evicted", toEvict, "remaining", maxFiles) }