Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 0448c6d

Browse files
committed
fs: Return ErrNotExist in ArchiveFS
Other minor fixes
1 parent 2731b1c commit 0448c6d

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

archiver_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,3 @@ func TestSkipList(t *testing.T) {
113113
}
114114
}
115115
}
116-
117-
func TestPathWithoutTopDir(t *testing.T) {
118-
for i, tc := range []struct {
119-
input, expect string
120-
}{
121-
{
122-
input: "a/b/c",
123-
expect: "b/c",
124-
},
125-
{
126-
input: "b/c",
127-
expect: "c",
128-
},
129-
{
130-
input: "c",
131-
expect: "",
132-
},
133-
{
134-
input: "",
135-
expect: "",
136-
},
137-
} {
138-
if actual := pathWithoutTopDir(tc.input); actual != tc.expect {
139-
t.Errorf("Test %d (input=%s): Expected '%s' but got '%s'", i, tc.input, tc.expect, actual)
140-
}
141-
}
142-
}

fs.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ func (f ArchiveFS) Open(name string) (fs.File, error) {
308308
if err != nil {
309309
return nil, err
310310
}
311+
if fsFile == nil {
312+
return nil, fs.ErrNotExist
313+
}
311314

312315
return fsFile, nil
313316
}
@@ -472,7 +475,7 @@ func TopDirReadDir(fsys fs.ReadDirFS, name string) ([]fs.DirEntry, error) {
472475
func pathWithoutTopDir(fpath string) string {
473476
slashIdx := strings.Index(fpath, "/")
474477
if slashIdx < 0 {
475-
return ""
478+
return fpath
476479
}
477480
return fpath[slashIdx+1:]
478481
}

fs_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package archiver
2+
3+
import "testing"
4+
5+
func TestPathWithoutTopDir(t *testing.T) {
6+
for i, tc := range []struct {
7+
input, expect string
8+
}{
9+
{
10+
input: "a/b/c",
11+
expect: "b/c",
12+
},
13+
{
14+
input: "b/c",
15+
expect: "c",
16+
},
17+
{
18+
input: "c",
19+
expect: "c",
20+
},
21+
{
22+
input: "",
23+
expect: "",
24+
},
25+
} {
26+
if actual := pathWithoutTopDir(tc.input); actual != tc.expect {
27+
t.Errorf("Test %d (input=%s): Expected '%s' but got '%s'", i, tc.input, tc.expect, actual)
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)