Skip to content

Commit 3ea17e5

Browse files
committed
refactor(serverHandler/archive): get filter from handler directly
use `(*serverHandler.handler).filter` instead of passing from outside.
1 parent 98eaf1a commit 3ea17e5

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

src/serverHandler/archive.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ import (
99
"strings"
1010
)
1111

12-
type filterCallback func([]os.FileInfo) []os.FileInfo
1312
type archiveCallback func(f *os.File, fInfo os.FileInfo, relPath string) error
1413

1514
func (h *handler) visitFs(
1615
initFsPath, rawRequestPath, relPath string,
1716
statFs bool,
18-
filterCallback filterCallback,
1917
archiveCallback archiveCallback,
2018
) {
2119
alias, hasAlias := h.aliases.byUrlPath(rawRequestPath)
@@ -65,7 +63,7 @@ func (h *handler) visitFs(
6563
if h.errHandler.LogError(err) {
6664
return err
6765
}
68-
childInfos = filterCallback(childInfos)
66+
childInfos = h.FilterItems(childInfos)
6967
}
7068

7169
return nil
@@ -107,17 +105,17 @@ func (h *handler) visitFs(
107105
childRelPath := relPath + childPath
108106

109107
if childAliasedFsPath, hasChildAlias := childAliases[childRawRequestPath]; hasChildAlias {
110-
h.visitFs(childAliasedFsPath, childRawRequestPath, childRelPath, statFs, filterCallback, archiveCallback)
108+
h.visitFs(childAliasedFsPath, childRawRequestPath, childRelPath, statFs, archiveCallback)
111109
delete(childAliases, childRawRequestPath) // delete walked alias
112110
} else {
113-
h.visitFs(childFsPath, childRawRequestPath, childRelPath, statFs, filterCallback, archiveCallback)
111+
h.visitFs(childFsPath, childRawRequestPath, childRelPath, statFs, archiveCallback)
114112
}
115113
}
116114

117115
// rest aliases are standalone aliases that not shadows exists dir/file
118116
for childRawRequestPath, childAliasedFsPath := range childAliases {
119117
childRelPath := relPath + "/" + path.Base(childRawRequestPath)
120-
h.visitFs(childAliasedFsPath, childRawRequestPath, childRelPath, statFs, filterCallback, archiveCallback)
118+
h.visitFs(childAliasedFsPath, childRawRequestPath, childRelPath, statFs, archiveCallback)
121119
}
122120
}
123121
}
@@ -128,7 +126,6 @@ func (h *handler) archive(
128126
pageData *responseData,
129127
fileSuffix string,
130128
contentType string,
131-
filterCallback filterCallback,
132129
cbWriteFile archiveCallback,
133130
) {
134131
var itemName string
@@ -152,7 +149,6 @@ func (h *handler) archive(
152149
pageData.rawReqPath,
153150
"",
154151
!h.emptyRoot,
155-
filterCallback,
156152
func(f *os.File, fInfo os.FileInfo, relPath string) error {
157153
go h.logArchive(targetFilename, relPath, r)
158154
err := cbWriteFile(f, fInfo, relPath)

src/serverHandler/archiveTar.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func (h *handler) tar(w http.ResponseWriter, r *http.Request, pageData *response
6060
pageData,
6161
".tar",
6262
"application/octet-stream",
63-
h.FilterItems,
6463
func(f *os.File, fInfo os.FileInfo, relPath string) error {
6564
return writeTar(tw, f, fInfo, relPath)
6665
},
@@ -89,7 +88,6 @@ func (h *handler) tgz(w http.ResponseWriter, r *http.Request, pageData *response
8988
pageData,
9089
".tar.gz",
9190
"application/octet-stream",
92-
h.FilterItems,
9391
func(f *os.File, fInfo os.FileInfo, relPath string) error {
9492
return writeTar(tw, f, fInfo, relPath)
9593
},

src/serverHandler/archiveZip.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func (h *handler) zip(w http.ResponseWriter, r *http.Request, pageData *response
5050
pageData,
5151
".zip",
5252
"application/zip",
53-
h.FilterItems,
5453
func(f *os.File, fInfo os.FileInfo, relPath string) error {
5554
return writeZip(zipWriter, f, fInfo, relPath)
5655
},

0 commit comments

Comments
 (0)