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.
This commit is contained in:
Martin Atkins 2021-10-12 11:04:01 -07:00
parent e804fce63a
commit d76759a6a9

View File

@ -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 {