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:
parent
e804fce63a
commit
d76759a6a9
|
@ -258,7 +258,7 @@ func (fs snapshotFS) Open(name string) (afero.File, error) {
|
||||||
filenames = append(filenames, n)
|
filenames = append(filenames, n)
|
||||||
}
|
}
|
||||||
sort.Strings(filenames)
|
sort.Strings(filenames)
|
||||||
return snapshotDir{
|
return &snapshotDir{
|
||||||
filenames: filenames,
|
filenames: filenames,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ func (fs snapshotFS) Stat(name string) (os.FileInfo, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_, isDir := f.(snapshotDir)
|
_, isDir := f.(*snapshotDir)
|
||||||
return snapshotFileInfo{
|
return snapshotFileInfo{
|
||||||
name: filepath.Base(name),
|
name: filepath.Base(name),
|
||||||
isDir: isDir,
|
isDir: isDir,
|
||||||
|
@ -377,9 +377,9 @@ type snapshotDir struct {
|
||||||
at int
|
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)
|
names, err := f.Readdirnames(count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -394,7 +394,7 @@ func (f snapshotDir) Readdir(count int) ([]os.FileInfo, error) {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f snapshotDir) Readdirnames(count int) ([]string, error) {
|
func (f *snapshotDir) Readdirnames(count int) ([]string, error) {
|
||||||
var outLen int
|
var outLen int
|
||||||
names := f.filenames[f.at:]
|
names := f.filenames[f.at:]
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
|
|
Loading…
Reference in New Issue