append '/' to end of dirs in directory listings

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
development
kim (grufwub) 4 years ago
parent b14b3302b3
commit 67f249c242

@ -127,7 +127,7 @@ func handleDirectory(client *core.Client, file *os.File, p *core.Path) *errors.E
// Add directory heading, empty line and a back line
dirContents = append(dirContents, []byte("["+core.Hostname+p.Selector()+"]\n\n")...)
dirContents = append(dirContents, []byte("=> /"+dirSel+" ..\n")...)
dirContents = append(dirContents, []byte("=> "+dirSel+" ..\n")...)
// Scan directory and build lines
err = core.ScanDirectory(
@ -137,6 +137,11 @@ func handleDirectory(client *core.Client, file *os.File, p *core.Path) *errors.E
// Calculate escaped selector path
sel := core.EscapePath(fp.Selector())
// If it's a dir, append final '/' to selector
if file.IsDir() {
sel += "/"
}
// Append new formatted file listing
dirContents = append(dirContents, []byte("=> "+sel+" "+file.Name()+"\n")...)
},

@ -66,7 +66,7 @@ func appendFileListing(b []byte, file os.FileInfo, p *core.Path) []byte {
// Handle file type
switch {
case file.Mode().IsDir():
return append(b, buildLine(typeDirectory, file.Name(), p.Selector(), core.Hostname, core.Port)...)
return append(b, buildLine(typeDirectory, file.Name(), p.Selector()+"/", core.Hostname, core.Port)...)
case file.Mode().IsRegular():
t := getItemType(file.Name())
return append(b, buildLine(t, file.Name(), p.Selector(), core.Hostname, core.Port)...)

Loading…
Cancel
Save