From d76759a6a961b1b20886d6b6528436257117ecf4 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 12 Oct 2021 11:04:01 -0700 Subject: [PATCH] configs/configload: snapshotDir must be used via pointer A snapshotDir tracks its current position as part of its state, so we need to use it via pointer rather than value so that Readdirnames can actually update that position, or else we'll just get stuck at position zero. In practice this wasn't hurting anything because we only call Readdir once on our snapshots, to read the whole directory at once. Still nice to fix to avoid a gotcha for future maintenence, though. --- internal/configs/configload/loader_snapshot.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/configs/configload/loader_snapshot.go b/internal/configs/configload/loader_snapshot.go index c1b54b8c2..915665f83 100644 --- a/internal/configs/configload/loader_snapshot.go +++ b/internal/configs/configload/loader_snapshot.go @@ -258,7 +258,7 @@ func (fs snapshotFS) Open(name string) (afero.File, error) { filenames = append(filenames, n) } sort.Strings(filenames) - return snapshotDir{ + return &snapshotDir{ filenames: filenames, }, nil } @@ -310,7 +310,7 @@ func (fs snapshotFS) Stat(name string) (os.FileInfo, error) { if err != nil { return nil, err } - _, isDir := f.(snapshotDir) + _, isDir := f.(*snapshotDir) return snapshotFileInfo{ name: filepath.Base(name), isDir: isDir, @@ -377,9 +377,9 @@ type snapshotDir struct { at int } -var _ afero.File = snapshotDir{} +var _ afero.File = (*snapshotDir)(nil) -func (f snapshotDir) Readdir(count int) ([]os.FileInfo, error) { +func (f *snapshotDir) Readdir(count int) ([]os.FileInfo, error) { names, err := f.Readdirnames(count) if err != nil { return nil, err @@ -394,7 +394,7 @@ func (f snapshotDir) Readdir(count int) ([]os.FileInfo, error) { return ret, nil } -func (f snapshotDir) Readdirnames(count int) ([]string, error) { +func (f *snapshotDir) Readdirnames(count int) ([]string, error) { var outLen int names := f.filenames[f.at:] if count > 0 {