@@ -26,29 +26,46 @@ func (h *handler) visitFs(
26
26
fsPath = initFsPath
27
27
}
28
28
29
- f , err := os .Open (fsPath )
30
- if f != nil {
31
- defer f .Close ()
32
- }
33
- h .errHandler .LogError (err )
34
-
35
29
var fInfo os.FileInfo
36
- if err != nil {
37
- if os .IsExist (err ) {
38
- return
30
+ var childInfos []os.FileInfo
31
+
32
+ err := func () error {
33
+ f , err := os .Open (fsPath )
34
+ if f != nil {
35
+ defer f .Close ()
39
36
}
40
- fInfo = newFakeFileInfo (path .Base (fsPath ), true )
41
- } else {
42
- fInfo , err = f .Stat ()
43
- if h .errHandler .LogError (err ) {
44
- return
37
+ h .errHandler .LogError (err )
38
+
39
+ if err != nil {
40
+ if os .IsExist (err ) {
41
+ return err
42
+ }
43
+ fInfo = newFakeFileInfo (path .Base (fsPath ), true ) // prefix path for alias
44
+ } else {
45
+ fInfo , err = f .Stat ()
46
+ if h .errHandler .LogError (err ) {
47
+ return err
48
+ }
45
49
}
46
- }
47
50
48
- if len (relPath ) > 0 {
49
- if archiveCallback (f , fInfo , relPath ) != nil {
50
- return
51
+ if len (relPath ) > 0 {
52
+ if err := archiveCallback (f , fInfo , relPath ); err != nil {
53
+ return err
54
+ }
51
55
}
56
+
57
+ if f != nil && fInfo .IsDir () {
58
+ childInfos , err = f .Readdir (0 )
59
+ if h .errHandler .LogError (err ) {
60
+ return err
61
+ }
62
+ childInfos = filterCallback (childInfos )
63
+ }
64
+
65
+ return nil
66
+ }()
67
+ if err != nil {
68
+ return
52
69
}
53
70
54
71
if fInfo .IsDir () {
@@ -72,15 +89,6 @@ func (h *handler) visitFs(
72
89
}
73
90
}
74
91
75
- var childInfos []os.FileInfo
76
- if f != nil {
77
- childInfos , err = f .Readdir (0 )
78
- if h .errHandler .LogError (err ) {
79
- return
80
- }
81
- childInfos = filterCallback (childInfos )
82
- }
83
-
84
92
for _ , childInfo := range childInfos {
85
93
childPath := "/" + childInfo .Name ()
86
94
childFsPath := fsPath + childPath
@@ -99,7 +107,6 @@ func (h *handler) visitFs(
99
107
childRelPath := relPath + "/" + path .Base (childRawRequestPath )
100
108
h .visitFs (childAliasedFsPath , childRawRequestPath , childRelPath , filterCallback , archiveCallback )
101
109
}
102
-
103
110
}
104
111
}
105
112
0 commit comments