|
|
@ -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 |
|
|
|
} |