1
0

Added code to resolve directory symlinks.

This commit is contained in:
Alexander Andreev 2022-06-28 06:13:44 +04:00
parent 6261719742
commit 20a14eca95
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -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()) + "/",