Skip to content

Commit 0e022af

Browse files
committed
fix(serverHandler): consider aliased index file on fake directory
1 parent 59ff843 commit 0e022af

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/serverHandler/responseData.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ func getStatusByErr(err error) int {
214214
}
215215

216216
func (h *handler) stateIndexFile(rawReqPath, baseDir string, baseItem os.FileInfo) (file *os.File, item os.FileInfo, err error) {
217-
if baseItem == nil || !baseItem.IsDir() || h.emptyRoot || len(h.dirIndexes) == 0 {
217+
if len(h.dirIndexes) == 0 {
218218
return
219219
}
220220

221221
for _, index := range h.dirIndexes {
222222
for _, alias := range h.aliases {
223-
if rawReqPath+"/"+index != alias.urlPath {
223+
if path.Clean(rawReqPath+"/"+index) != alias.urlPath {
224224
continue
225225
}
226226
file, item, err = stat(alias.fsPath, true)
@@ -235,8 +235,12 @@ func (h *handler) stateIndexFile(rawReqPath, baseDir string, baseItem os.FileInf
235235
}
236236
}
237237

238+
if baseItem == nil || !baseItem.IsDir() || h.emptyRoot {
239+
return
240+
}
241+
238242
for _, index := range h.dirIndexes {
239-
file, item, err = stat(baseDir+"/"+index, true)
243+
file, item, err = stat(path.Clean(baseDir+"/"+index), true)
240244
if err != nil && file != nil {
241245
file.Close()
242246
}

test/case/008.alias.dir.index.bash

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
source "$root"/lib.bash
44

5-
"$ghfs" -l 3003 -r "$fs"/vhost1 -I index.txt -a :/hello/index.txt:"$fs"/vhost1/world/index.txt &
5+
"$ghfs" -l 3003 -r "$fs"/vhost1 -I index.txt -a :/foo/bar:"$fs"/vhost2/ -a :/foo/index.txt:"$fs"/vhost1/go/index.txt -E '' &
66
sleep 0.05 # wait server ready
77

8-
world=$(curl_get_body http://127.0.0.1:3003/hello)
9-
assert "$world" 'vhost1/world/index.txt'
8+
world=$(curl_get_body http://127.0.0.1:3003/foo)
9+
assert "$world" 'vhost1/go/index.txt'
1010

1111
kill %1

0 commit comments

Comments
 (0)