Skip to content
Permalink
Browse files

browse: Fix symlink indicators for files in folders other than cwd

  • Loading branch information...
mholt committed Jun 2, 2017
1 parent 132f2a9 commit 6b8e40b3fb4553142aa514fbfd3b0a5ce805fd12
Showing with 9 additions and 4 deletions.
  1. +9 −4 caddyhttp/browse/browse.go
@@ -9,6 +9,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"sort"
"strconv"
"strings"
@@ -259,7 +260,7 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config
url := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name

fileinfos = append(fileinfos, FileInfo{
IsDir: f.IsDir() || isSymlinkTargetDir(f),
IsDir: f.IsDir() || isSymlinkTargetDir(f, urlPath, config),
IsSymlink: isSymlink(f),
Name: f.Name(),
Size: f.Size(),
@@ -286,15 +287,19 @@ func isSymlink(f os.FileInfo) bool {

// isSymlinkTargetDir return true if f's symbolic link target
// is a directory. Return false if not a symbolic link.
func isSymlinkTargetDir(f os.FileInfo) bool {
func isSymlinkTargetDir(f os.FileInfo, urlPath string, config *Config) bool {
if !isSymlink(f) {
return false
}
target, err := os.Readlink(f.Name())
fullPath := func(fileName string) string {
fullPath := filepath.Join(string(config.Fs.Root.(http.Dir)), urlPath, fileName)
return filepath.Clean(fullPath)
}
target, err := os.Readlink(fullPath(f.Name()))
if err != nil {
return false
}
targetInfo, err := os.Lstat(target)
targetInfo, err := os.Lstat(fullPath(target))
if err != nil {
return false
}

0 comments on commit 6b8e40b

Please sign in to comment.
You can’t perform that action at this time.