Browse Source

mount: ensure symlink parent directory is tracked

fix https://github.com/chrislusf/seaweedfs/issues/3373
pull/3335/merge
chrislu 2 years ago
parent
commit
e0eda52c54
  1. 15
      weed/mount/inode_to_path.go
  2. 6
      weed/mount/weedfs.go

15
weed/mount/inode_to_path.go

@ -5,6 +5,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
"sync" "sync"
"time"
) )
type InodeToPath struct { type InodeToPath struct {
@ -52,6 +53,20 @@ func NewInodeToPath(root util.FullPath) *InodeToPath {
return t return t
} }
// EnsurePath make sure the full path is tracked, used by symlink.
func (i *InodeToPath) EnsurePath(path util.FullPath, isDirectory bool) bool {
for {
dir, _ := path.DirAndName()
if dir == "/" {
return true
}
if i.EnsurePath(util.FullPath(dir), true) {
i.Lookup(path, time.Now().Unix(), isDirectory, false, 0, false)
}
}
return false
}
func (i *InodeToPath) Lookup(path util.FullPath, unixTime int64, isDirectory bool, isHardlink bool, possibleInode uint64, isLookup bool) uint64 { func (i *InodeToPath) Lookup(path util.FullPath, unixTime int64, isDirectory bool, isHardlink bool, possibleInode uint64, isLookup bool) uint64 {
i.Lock() i.Lock()
defer i.Unlock() defer i.Unlock()

6
weed/mount/weedfs.go

@ -144,8 +144,10 @@ func (wfs *WFS) maybeReadEntry(inode uint64, followSymLink bool) (path util.Full
if entry != nil && entry.Attributes != nil && entry.Attributes.Inode != 0 { if entry != nil && entry.Attributes != nil && entry.Attributes.Inode != 0 {
targetInode = entry.Attributes.Inode targetInode = entry.Attributes.Inode
} }
target := filepath.Join(string(path), "../"+entry.Attributes.SymlinkTarget)
entry, status = wfs.maybeLoadEntry(util.FullPath(target))
target := util.FullPath(filepath.Join(string(path), "../"+entry.Attributes.SymlinkTarget))
targetParent, _ := target.DirAndName()
wfs.inodeToPath.EnsurePath(util.FullPath(targetParent), true)
entry, status = wfs.maybeLoadEntry(target)
} }
return return
} }

Loading…
Cancel
Save