1
0
Fork 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
1 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,8 @@ package files
import (
"io/ioutil"
"net/url"
"os"
"path/filepath"
"time"
)
@ -29,7 +31,15 @@ func ScanDirectory(path, urlBase string) (entries []DirEntry, stats DirStats, er
dir, err := ioutil.ReadDir(path)
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{
Name: entry.Name(),
Link: url.PathEscape(entry.Name()) + "/",