Skip to content

Commit 7d646d8

Browse files
committed
refactor(archive): simplify logic
- set `statFs` to `true` if found alias when iterating child infos - skip detect `statFs` on entering loop - skip detect alias and fs path on entering loop, use passed in param
1 parent 4d005da commit 7d646d8

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/serverHandler/archive.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,10 @@ import (
1111
type archiveCallback func(f *os.File, fInfo os.FileInfo, relPath string) error
1212

1313
func (h *handler) visitFs(
14-
initFsPath, rawRequestPath, relPath string,
14+
fsPath, rawReqPath, relPath string,
1515
statFs bool,
1616
archiveCallback archiveCallback,
1717
) {
18-
var fsPath string
19-
alias, hasAlias := h.aliases.byUrlPath(rawRequestPath)
20-
if hasAlias {
21-
fsPath = alias.fsPath
22-
if alias.urlPath != "/" {
23-
statFs = true
24-
}
25-
} else {
26-
fsPath = initFsPath
27-
}
28-
2918
var fInfo os.FileInfo
3019
var childInfos []os.FileInfo
3120
// wrap func to run defer ASAP
@@ -74,20 +63,20 @@ func (h *handler) visitFs(
7463
}
7564

7665
if fInfo.IsDir() {
77-
childInfos, _, _ := h.mergeAlias(rawRequestPath, fInfo, childInfos)
66+
childInfos, _, _ := h.mergeAlias(rawReqPath, fInfo, childInfos)
7867
childInfos = h.FilterItems(childInfos)
7968

8069
// childInfo can be regular dir/file, or aliased item that shadows regular dir/file
8170
for _, childInfo := range childInfos {
8271
childPath := "/" + childInfo.Name()
8372
childFsPath := fsPath + childPath
84-
childRawRequestPath := util.CleanUrlPath(rawRequestPath + childPath)
73+
childRawReqPath := util.CleanUrlPath(rawReqPath + childPath)
8574
childRelPath := relPath + childPath
8675

87-
if childAlias, hasChildAlias := h.aliases.byUrlPath(childRawRequestPath); hasChildAlias {
88-
h.visitFs(childAlias.fsPath, childRawRequestPath, childRelPath, statFs, archiveCallback)
76+
if childAlias, hasChildAlias := h.aliases.byUrlPath(childRawReqPath); hasChildAlias {
77+
h.visitFs(childAlias.fsPath, childRawReqPath, childRelPath, true, archiveCallback)
8978
} else {
90-
h.visitFs(childFsPath, childRawRequestPath, childRelPath, statFs, archiveCallback)
79+
h.visitFs(childFsPath, childRawReqPath, childRelPath, statFs, archiveCallback)
9180
}
9281
}
9382
}

0 commit comments

Comments
 (0)