diff --git a/drivers/local/driver.go b/drivers/local/driver.go index 5679f468..303a491d 100644 --- a/drivers/local/driver.go +++ b/drivers/local/driver.go @@ -77,12 +77,17 @@ func (d *Local) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([ thumb = utils.EncodePath(thumb, true) thumb += "?type=thumb" } + isFolder := f.IsDir() || isSymlinkDir(f, fullPath) + size := f.Size() + if isFolder { + size = 0 + } file := model.ObjThumb{ Object: model.Object{ Name: f.Name(), Modified: f.ModTime(), - Size: f.Size(), - IsFolder: f.IsDir(), + Size: size, + IsFolder: isFolder, }, Thumbnail: model.Thumbnail{ Thumbnail: thumb, @@ -101,12 +106,17 @@ func (d *Local) Get(ctx context.Context, path string) (model.Obj, error) { } return nil, err } + isFolder := f.IsDir() || isSymlinkDir(f, path) + size := f.Size() + if isFolder { + size = 0 + } file := model.Object{ Path: path, Name: f.Name(), Modified: f.ModTime(), - Size: f.Size(), - IsFolder: f.IsDir(), + Size: size, + IsFolder: isFolder, } return &file, nil } diff --git a/drivers/local/util.go b/drivers/local/util.go index 469c3dc0..d440460f 100644 --- a/drivers/local/util.go +++ b/drivers/local/util.go @@ -1 +1,22 @@ package local + +import ( + "io/fs" + "os" + "path/filepath" +) + +func isSymlinkDir(f fs.FileInfo, path string) bool { + if f.Mode()&os.ModeSymlink == os.ModeSymlink { + dst, err := os.Readlink(filepath.Join(path, f.Name())) + if err != nil { + return false + } + stat, err := os.Stat(dst) + if err != nil { + return false + } + return stat.IsDir() + } + return false +}