Skip to content

Commit

Permalink
fix(local): directory handle (#2262)
Browse files Browse the repository at this point in the history
* fix(local): check symlink dir

* fix(local): set size of dir to 0 (close #2264)
  • Loading branch information
BoYanZh authored Nov 9, 2022
1 parent e05e2fd commit cdcbfb2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
18 changes: 14 additions & 4 deletions drivers/local/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
21 changes: 21 additions & 0 deletions drivers/local/util.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit cdcbfb2

Please sign in to comment.