Commit 132f2a9c authored by Jonas Östanbäck's avatar Jonas Östanbäck Committed by Matt Holt

browse: Show symbolic links and target's type properly (#1667)

* Browse: Show symbolic links and targets type properly
 * gofmt
Signed-off-by: default avatarJonas Östanbäck <jonas.ostanback@gmail.com>

* Move symbolic link check in to isSymlinkTargetDir
Signed-off-by: default avatarJonas Östanbäck <jonas.ostanback@gmail.com>

* Revert template change and show sym link folders as normal folders

* browse: Updated icons including symlink indicators
parent baf269d4
...@@ -118,6 +118,7 @@ type FileInfo struct { ...@@ -118,6 +118,7 @@ type FileInfo struct {
ModTime time.Time ModTime time.Time
Mode os.FileMode Mode os.FileMode
IsDir bool IsDir bool
IsSymlink bool
} }
// HumanSize returns the size of the file as a human-readable string // HumanSize returns the size of the file as a human-readable string
...@@ -258,7 +259,8 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config ...@@ -258,7 +259,8 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config
url := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name url := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name
fileinfos = append(fileinfos, FileInfo{ fileinfos = append(fileinfos, FileInfo{
IsDir: f.IsDir(), IsDir: f.IsDir() || isSymlinkTargetDir(f),
IsSymlink: isSymlink(f),
Name: f.Name(), Name: f.Name(),
Size: f.Size(), Size: f.Size(),
URL: url.String(), URL: url.String(),
...@@ -277,6 +279,28 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config ...@@ -277,6 +279,28 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config
}, hasIndexFile }, hasIndexFile
} }
// isSymlink return true if f is a symbolic link
func isSymlink(f os.FileInfo) bool {
return f.Mode()&os.ModeSymlink != 0
}
// 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 {
if !isSymlink(f) {
return false
}
target, err := os.Readlink(f.Name())
if err != nil {
return false
}
targetInfo, err := os.Lstat(target)
if err != nil {
return false
}
return targetInfo.IsDir()
}
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met. // ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
// If so, control is handed over to ServeListing. // If so, control is handed over to ServeListing.
func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment