afero icon indicating copy to clipboard operation
afero copied to clipboard

`[zipFS]` readdir \: The system cannot find the file specified.

Open acabarbaye opened this issue 1 year ago • 1 comments

I have run the following test on Windows with attached valid zip file testunzip.zip and I am getting the following errors

readdir \: The system cannot find the file specified.

when calling Readdirnames or Readdir

func TestZipFS2(t *testing.T) {
	zrc, err := zip.OpenReader("testdata/testunzip.zip")
	if err != nil {
		t.Fatal(err)
	}
	zfs := New(&zrc.Reader)
	a := &afero.Afero{Fs: zfs}

	d, err := a.Open("/")
	if d == nil {
		t.Error(`Open("/") returns nil`)
	}
	if err != nil {
		t.Errorf(`Open("/"): err = %v`, err)
	}
	if s, _ := d.Stat(); !s.IsDir() {
		t.Error(`expected root ("/") to be a directory`)
	}
	if n := d.Name(); n != string(filepath.Separator) {
		t.Errorf("Wrong Name() of root directory: Expected: '%c', got '%s'", filepath.Separator, n)
	}

	if fileList, err := d.Readdirnames(-1); err != nil {
		t.Error(err)
	} else if len(fileList) != 1 {
		t.Errorf("expected 1 item at the root, got %d", len(fileList))
	}

	if fileList, err := d.Readdir(-1); err != nil {
		t.Error(err)
	} else if len(fileList) !
= 1 {
		t.Errorf("expected 1 item at the root, got %d", len(fileList))
	}
}

acabarbaye avatar Jul 28 '23 17:07 acabarbaye

i suspect this is because zipfs uses filepath instead of path

https://github.com/spf13/afero/blob/master/zipfs/fs.go#L40 https://github.com/spf13/afero/blob/master/zipfs/file.go#L111

on windows, filepath will separate with '', but packages such as zip (and embed, and others) will only ever use posix-style "/" even on windows, so path should be used.

i think changing filepath -> path here is all that's needed, since the underlying zipfs implementation will never change.

elee1766 avatar Jan 15 '24 05:01 elee1766