|
|
@ -27,7 +27,7 @@ import ( |
|
|
|
"github.com/dustin/go-humanize" |
|
|
|
) |
|
|
|
|
|
|
|
func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root, urlPath string, repl *caddy.Replacer) browseTemplateContext { |
|
|
|
func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root, urlPath string, repl *caddy.Replacer) (browseTemplateContext, error) { |
|
|
|
filesToHide := fsrv.transformHidePaths(repl) |
|
|
|
|
|
|
|
var dirCount, fileCount int |
|
|
@ -52,11 +52,21 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root |
|
|
|
fileCount++ |
|
|
|
} |
|
|
|
|
|
|
|
fileIsSymlink := isSymlink(f) |
|
|
|
size := f.Size() |
|
|
|
if fileIsSymlink { |
|
|
|
info, err := os.Stat(name) |
|
|
|
if err != nil { |
|
|
|
return browseTemplateContext{}, err |
|
|
|
} |
|
|
|
size = info.Size() |
|
|
|
} |
|
|
|
|
|
|
|
fileInfos = append(fileInfos, fileInfo{ |
|
|
|
IsDir: isDir, |
|
|
|
IsSymlink: isSymlink(f), |
|
|
|
Name: f.Name(), |
|
|
|
Size: f.Size(), |
|
|
|
IsSymlink: fileIsSymlink, |
|
|
|
Name: name, |
|
|
|
Size: size, |
|
|
|
URL: u.String(), |
|
|
|
ModTime: f.ModTime().UTC(), |
|
|
|
Mode: f.Mode(), |
|
|
@ -70,7 +80,7 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root |
|
|
|
Items: fileInfos, |
|
|
|
NumDirs: dirCount, |
|
|
|
NumFiles: fileCount, |
|
|
|
} |
|
|
|
}, nil |
|
|
|
} |
|
|
|
|
|
|
|
// browseTemplateContext provides the template context for directory listings.
|
|
|
|