1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-22 15:57:07 +00:00

Fix and simplify fs.Reader

fakeDir.{Readdir,Readdirnames} weren't handling the case n == 0
correctly. fakeFileInfo.sys is always nil, so omit the field.
This commit is contained in:
greatroar 2020-03-02 21:33:39 +01:00
parent c504aa505c
commit 1557c58eef

View file

@ -275,7 +275,7 @@ type fakeDir struct {
} }
func (d fakeDir) Readdirnames(n int) ([]string, error) { func (d fakeDir) Readdirnames(n int) ([]string, error) {
if n >= 0 { if n > 0 {
return nil, errors.New("not implemented") return nil, errors.New("not implemented")
} }
names := make([]string, 0, len(d.entries)) names := make([]string, 0, len(d.entries))
@ -287,7 +287,7 @@ func (d fakeDir) Readdirnames(n int) ([]string, error) {
} }
func (d fakeDir) Readdir(n int) ([]os.FileInfo, error) { func (d fakeDir) Readdir(n int) ([]os.FileInfo, error) {
if n >= 0 { if n > 0 {
return nil, errors.New("not implemented") return nil, errors.New("not implemented")
} }
return d.entries, nil return d.entries, nil
@ -299,7 +299,6 @@ type fakeFileInfo struct {
size int64 size int64
mode os.FileMode mode os.FileMode
modtime time.Time modtime time.Time
sys interface{}
} }
func (fi fakeFileInfo) Name() string { func (fi fakeFileInfo) Name() string {
@ -323,5 +322,5 @@ func (fi fakeFileInfo) IsDir() bool {
} }
func (fi fakeFileInfo) Sys() interface{} { func (fi fakeFileInfo) Sys() interface{} {
return fi.sys return nil
} }