Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
acabarbaye opened this issue Jul 28, 2023 · 1 comment
Open

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

acabarbaye opened this issue Jul 28, 2023 · 1 comment

Comments

@acabarbaye
Copy link

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 acabarbaye changed the title [zipFS readdir \: The system cannot find the file specified. [zipFS] readdir \: The system cannot find the file specified. Jul 28, 2023
@elee1766
Copy link

elee1766 commented Jan 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants