aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/dir.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/filesys/dir.go')
-rw-r--r--weed/filesys/dir.go34
1 files changed, 29 insertions, 5 deletions
diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go
index fbe2f4f3a..4978fa8dc 100644
--- a/weed/filesys/dir.go
+++ b/weed/filesys/dir.go
@@ -9,11 +9,14 @@ import (
"bazil.org/fuse/fs"
"bazil.org/fuse"
"github.com/chrislusf/seaweedfs/weed/filer"
+ "sync"
)
type Dir struct {
- Path string
- wfs *WFS
+ Path string
+ NodeMap map[string]fs.Node
+ NodeMapLock sync.Mutex
+ wfs *WFS
}
func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error {
@@ -21,16 +24,30 @@ func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error {
return nil
}
-func (dir *Dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
+func (dir *Dir) Lookup(ctx context.Context, name string) (node fs.Node, err error) {
+
+ dir.NodeMapLock.Lock()
+ defer dir.NodeMapLock.Unlock()
+
+ if dir.NodeMap == nil {
+ dir.NodeMap = make(map[string]fs.Node)
+ }
+
+ if node, ok := dir.NodeMap[name]; ok {
+ return node, nil
+ }
+
if entry, err := filer.LookupDirectoryEntry(dir.wfs.filer, dir.Path, name); err == nil {
if !entry.Found {
return nil, fuse.ENOENT
}
if entry.FileId != "" {
- return &File{FileId: filer.FileId(entry.FileId), Name: name, wfs: dir.wfs}, nil
+ node = &File{FileId: filer.FileId(entry.FileId), Name: name, wfs: dir.wfs}
} else {
- return &Dir{Path: path.Join(dir.Path, name), wfs: dir.wfs}, nil
+ node = &Dir{Path: path.Join(dir.Path, name), wfs: dir.wfs}
}
+ dir.NodeMap[name] = node
+ return node, nil
}
return nil, fuse.ENOENT
@@ -54,10 +71,17 @@ func (dir *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
}
func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
+
+ dir.NodeMapLock.Lock()
+ defer dir.NodeMapLock.Unlock()
+
name := path.Join(dir.Path, req.Name)
err := filer.DeleteDirectoryOrFile(dir.wfs.filer, name, req.Dir)
if err != nil {
fmt.Printf("Delete file %s [ERROR] %s\n", name, err)
+ } else {
+ delete(dir.NodeMap, req.Name)
}
+
return err
}