diff -Nru golang-github-spf13-afero-1.2.1/composite_test.go golang-github-spf13-afero-1.2.2/composite_test.go --- golang-github-spf13-afero-1.2.1/composite_test.go 2019-01-30 08:29:40.000000000 +0000 +++ golang-github-spf13-afero-1.2.2/composite_test.go 2019-03-26 12:07:55.000000000 +0000 @@ -404,7 +404,7 @@ } // #194 -func TestUniontFileReaddirEmpty(t *testing.T) { +func TestUnionFileReaddirEmpty(t *testing.T) { osFs := NewOsFs() base := NewMemMapFs() @@ -439,7 +439,41 @@ } } -func TestUniontFileReaddirAskForTooMany(t *testing.T) { +// #197 +func TestUnionFileReaddirDuplicateEmpty(t *testing.T) { + base := NewMemMapFs() + dir, err := TempDir(base, "", "empty-dir") + if err != nil { + t.Fatal(err) + } + + // Overlay shares same empty directory as base + overlay := NewMemMapFs() + err = overlay.Mkdir(dir, 0700) + if err != nil { + t.Fatal(err) + } + + ufs := &CopyOnWriteFs{base: base, layer: overlay} + + f, err := ufs.Open(dir) + if err != nil { + t.Fatal(err) + } + defer f.Close() + + names, err := f.Readdirnames(0) + + if err == io.EOF { + t.Errorf("unexpected io.EOF error") + } + + if len(names) != 0 { + t.Fatal("should be empty") + } +} + +func TestUnionFileReaddirAskForTooMany(t *testing.T) { base := &MemMapFs{} overlay := &MemMapFs{} diff -Nru golang-github-spf13-afero-1.2.1/debian/changelog golang-github-spf13-afero-1.2.2/debian/changelog --- golang-github-spf13-afero-1.2.1/debian/changelog 2019-02-01 18:08:02.000000000 +0000 +++ golang-github-spf13-afero-1.2.2/debian/changelog 2019-04-14 09:20:52.000000000 +0000 @@ -1,3 +1,9 @@ +golang-github-spf13-afero (1.2.2-1) unstable; urgency=medium + + * New upstream version 1.2.2 + + -- Anthony Fok Sun, 14 Apr 2019 03:20:52 -0600 + golang-github-spf13-afero (1.2.1-1) unstable; urgency=medium * New upstream version 1.2.1 diff -Nru golang-github-spf13-afero-1.2.1/unionFile.go golang-github-spf13-afero-1.2.2/unionFile.go --- golang-github-spf13-afero-1.2.1/unionFile.go 2019-01-30 08:29:40.000000000 +0000 +++ golang-github-spf13-afero-1.2.2/unionFile.go 2019-03-26 12:07:55.000000000 +0000 @@ -155,8 +155,8 @@ } // Readdir will weave the two directories together and -// return a single view of the overlayed directories -// At the end of the directory view, the error is io.EOF. +// return a single view of the overlayed directories. +// At the end of the directory view, the error is io.EOF if c > 0. func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error) { var merge DirsMerger = f.Merger if merge == nil { @@ -187,11 +187,15 @@ f.files = append(f.files, merged...) } + if c <= 0 && len(f.files) == 0 { + return f.files, nil + } + if f.off >= len(f.files) { return nil, io.EOF } - if c == -1 { + if c <= 0 { return f.files[f.off:], nil }