mirror of https://github.com/Xhofe/alist
refactor(driver): Refactored directory link check logic (#9324)
- Use `filePath` variable to simplify path handling - Replace `isSymlinkDir` with `isLinkedDir` in `isFolder` check - Use simplified path variables in `times.Stat` function calls refactor(util): Optimized directory link check functions - Renamed `isSymlinkDir` to `isLinkedDir` to expand Windows platform support - Corrected path resolution logic to ensure link paths are absolute - Added error handling to prevent path resolution failuresmain beta
parent
e1800f18e4
commit
4f8bc478d5
|
@ -146,13 +146,14 @@ func (d *Local) FileInfoToObj(ctx context.Context, f fs.FileInfo, reqPath string
|
||||||
thumb += "?type=thumb&sign=" + sign.Sign(stdpath.Join(reqPath, f.Name()))
|
thumb += "?type=thumb&sign=" + sign.Sign(stdpath.Join(reqPath, f.Name()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isFolder := f.IsDir() || isSymlinkDir(f, fullPath)
|
filePath := filepath.Join(fullPath, f.Name())
|
||||||
|
isFolder := f.IsDir() || isLinkedDir(f, filePath)
|
||||||
var size int64
|
var size int64
|
||||||
if !isFolder {
|
if !isFolder {
|
||||||
size = f.Size()
|
size = f.Size()
|
||||||
}
|
}
|
||||||
var ctime time.Time
|
var ctime time.Time
|
||||||
t, err := times.Stat(stdpath.Join(fullPath, f.Name()))
|
t, err := times.Stat(filePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if t.HasBirthTime() {
|
if t.HasBirthTime() {
|
||||||
ctime = t.BirthTime()
|
ctime = t.BirthTime()
|
||||||
|
@ -161,7 +162,7 @@ func (d *Local) FileInfoToObj(ctx context.Context, f fs.FileInfo, reqPath string
|
||||||
|
|
||||||
file := model.ObjThumb{
|
file := model.ObjThumb{
|
||||||
Object: model.Object{
|
Object: model.Object{
|
||||||
Path: filepath.Join(fullPath, f.Name()),
|
Path: filePath,
|
||||||
Name: f.Name(),
|
Name: f.Name(),
|
||||||
Modified: f.ModTime(),
|
Modified: f.ModTime(),
|
||||||
Size: size,
|
Size: size,
|
||||||
|
@ -197,7 +198,7 @@ func (d *Local) Get(ctx context.Context, path string) (model.Obj, error) {
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
isFolder := f.IsDir() || isSymlinkDir(f, path)
|
isFolder := f.IsDir() || isLinkedDir(f, path)
|
||||||
size := f.Size()
|
size := f.Size()
|
||||||
if isFolder {
|
if isFolder {
|
||||||
size = 0
|
size = 0
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -18,14 +19,18 @@ import (
|
||||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isSymlinkDir(f fs.FileInfo, path string) bool {
|
func isLinkedDir(f fs.FileInfo, path string) bool {
|
||||||
if f.Mode()&os.ModeSymlink == os.ModeSymlink {
|
if f.Mode()&os.ModeSymlink == os.ModeSymlink || (runtime.GOOS == "windows" && f.Mode()&os.ModeIrregular != 0) {
|
||||||
dst, err := os.Readlink(filepath.Join(path, f.Name()))
|
dst, err := os.Readlink(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !filepath.IsAbs(dst) {
|
if !filepath.IsAbs(dst) {
|
||||||
dst = filepath.Join(path, dst)
|
dst = filepath.Join(filepath.Dir(path), dst)
|
||||||
|
}
|
||||||
|
dst, err = filepath.Abs(dst)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
stat, err := os.Stat(dst)
|
stat, err := os.Stat(dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue