Skip to content

Commit 5e9b85d

Browse files
committed
fixup symlinks listing appearance
closes #123
1 parent 31c8ee5 commit 5e9b85d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

gossa.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,17 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
100100
p.Title = template.HTML(html.EscapeString(title))
101101

102102
for _, el := range files {
103-
info, err := el.Info()
104-
if err != nil {
103+
info, errInfo := el.Info()
104+
el, err := os.Stat(fullPath + "/" + el.Name())
105+
if err != nil || errInfo != nil {
105106
log.Println("error - cant stat a file", err)
106107
continue
107108
}
108109

109110
if *skipHidden && strings.HasPrefix(el.Name(), ".") {
110111
continue // dont print hidden files if we're not allowed
111112
}
112-
if *symlinks && info.Mode()&os.ModeSymlink != 0 {
113+
if !*symlinks && info.Mode()&os.ModeSymlink != 0 {
113114
continue // dont follow symlinks if we're not allowed
114115
}
115116

@@ -126,7 +127,7 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
126127
} else {
127128
sl := strings.Split(name, ".")
128129
ext := strings.ToLower(sl[len(sl)-1])
129-
row := rowTemplate{name, template.URL(href), humanize(info.Size()), ext}
130+
row := rowTemplate{name, template.URL(href), humanize(el.Size()), ext}
130131
p.RowsFiles = append(p.RowsFiles, row)
131132
}
132133
}

gossa_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
238238
hasListing := strings.Contains(body0, `readme.md`)
239239
body1 = get(t, url+"/support/readme.md")
240240
hasReadme := strings.Contains(body1, `the master branch is automatically built and pushed`)
241+
body2 = get(t, url)
242+
hasMainListing := strings.Contains(body2, `href="support">support/</a>`)
241243

242244
if !testExtra && hasReadme {
243245
t.Fatal("error symlink file reached where illegal")
@@ -249,6 +251,11 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
249251
} else if testExtra && !hasListing {
250252
t.Fatal("error symlink folder unreachable")
251253
}
254+
if !testExtra && hasMainListing {
255+
t.Fatal("error symlink folder where illegal")
256+
} else if testExtra && !hasMainListing {
257+
t.Fatal("error symlink folder unreachable")
258+
}
252259

253260
if testExtra {
254261
fmt.Println("\r\n~~~~~~~~~~ test symlink mkdir & cleanup")

0 commit comments

Comments
 (0)