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
...@@ -112,12 +112,13 @@ func (l Listing) Breadcrumbs() []Crumb { ...@@ -112,12 +112,13 @@ func (l Listing) Breadcrumbs() []Crumb {
// FileInfo is the info about a particular file or directory // FileInfo is the info about a particular file or directory
type FileInfo struct { type FileInfo struct {
Name string Name string
Size int64 Size int64
URL string URL string
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,12 +259,13 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config ...@@ -258,12 +259,13 @@ 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),
Name: f.Name(), IsSymlink: isSymlink(f),
Size: f.Size(), Name: f.Name(),
URL: url.String(), Size: f.Size(),
ModTime: f.ModTime().UTC(), URL: url.String(),
Mode: f.Mode(), ModTime: f.ModTime().UTC(),
Mode: f.Mode(),
}) })
} }
...@@ -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