Added code to resolve directory symlinks.
This commit is contained in:
parent
6261719742
commit
20a14eca95
@ -3,6 +3,8 @@ package files
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,7 +31,15 @@ func ScanDirectory(path, urlBase string) (entries []DirEntry, stats DirStats, er
|
|||||||
dir, err := ioutil.ReadDir(path)
|
dir, err := ioutil.ReadDir(path)
|
||||||
for _, entry := range dir {
|
for _, entry := range dir {
|
||||||
|
|
||||||
if entry.IsDir() {
|
var isDirLink bool
|
||||||
|
if entry.Mode().Type().String()[0] == 'L' {
|
||||||
|
if slp, err := filepath.EvalSymlinks(filepath.Join(path, entry.Name())); err == nil {
|
||||||
|
lStat, _ := os.Lstat(slp)
|
||||||
|
isDirLink = lStat.IsDir()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if entry.IsDir() || isDirLink {
|
||||||
dirEntries = append(dirEntries, DirEntry{
|
dirEntries = append(dirEntries, DirEntry{
|
||||||
Name: entry.Name(),
|
Name: entry.Name(),
|
||||||
Link: url.PathEscape(entry.Name()) + "/",
|
Link: url.PathEscape(entry.Name()) + "/",
|
||||||
|
Loading…
Reference in New Issue
Block a user