Skip to content

Commit

Permalink
fs: Return ErrNotExist in ArchiveFS
Browse files Browse the repository at this point in the history
Other minor fixes
  • Loading branch information
mholt committed Jan 9, 2022
1 parent 2731b1c commit 0448c6d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
27 changes: 0 additions & 27 deletions archiver_test.go
Expand Up @@ -113,30 +113,3 @@ func TestSkipList(t *testing.T) {
}
}
}

func TestPathWithoutTopDir(t *testing.T) {
for i, tc := range []struct {
input, expect string
}{
{
input: "a/b/c",
expect: "b/c",
},
{
input: "b/c",
expect: "c",
},
{
input: "c",
expect: "",
},
{
input: "",
expect: "",
},
} {
if actual := pathWithoutTopDir(tc.input); actual != tc.expect {
t.Errorf("Test %d (input=%s): Expected '%s' but got '%s'", i, tc.input, tc.expect, actual)
}
}
}
5 changes: 4 additions & 1 deletion fs.go
Expand Up @@ -308,6 +308,9 @@ func (f ArchiveFS) Open(name string) (fs.File, error) {
if err != nil {
return nil, err
}
if fsFile == nil {
return nil, fs.ErrNotExist
}

return fsFile, nil
}
Expand Down Expand Up @@ -472,7 +475,7 @@ func TopDirReadDir(fsys fs.ReadDirFS, name string) ([]fs.DirEntry, error) {
func pathWithoutTopDir(fpath string) string {
slashIdx := strings.Index(fpath, "/")
if slashIdx < 0 {
return ""
return fpath
}
return fpath[slashIdx+1:]
}
Expand Down
30 changes: 30 additions & 0 deletions fs_test.go
@@ -0,0 +1,30 @@
package archiver

import "testing"

func TestPathWithoutTopDir(t *testing.T) {
for i, tc := range []struct {
input, expect string
}{
{
input: "a/b/c",
expect: "b/c",
},
{
input: "b/c",
expect: "c",
},
{
input: "c",
expect: "c",
},
{
input: "",
expect: "",
},
} {
if actual := pathWithoutTopDir(tc.input); actual != tc.expect {
t.Errorf("Test %d (input=%s): Expected '%s' but got '%s'", i, tc.input, tc.expect, actual)
}
}
}

0 comments on commit 0448c6d

Please sign in to comment.