You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
883 B

  1. package filesys
  2. import (
  3. "bazil.org/fuse/fs"
  4. "fmt"
  5. "google.golang.org/grpc"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. "github.com/karlseguin/ccache"
  8. )
  9. type WFS struct {
  10. filer string
  11. listDirectoryEntriesCache *ccache.Cache
  12. }
  13. func NewSeaweedFileSystem(filer string) *WFS {
  14. return &WFS{
  15. filer: filer,
  16. listDirectoryEntriesCache: ccache.New(ccache.Configure().MaxSize(6000).ItemsToPrune(100)),
  17. }
  18. }
  19. func (wfs *WFS) Root() (fs.Node, error) {
  20. return &Dir{Path: "/", wfs: wfs}, nil
  21. }
  22. func (wfs *WFS) withFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
  23. grpcConnection, err := grpc.Dial(wfs.filer, grpc.WithInsecure())
  24. if err != nil {
  25. return fmt.Errorf("fail to dial %s: %v", wfs.filer, err)
  26. }
  27. defer grpcConnection.Close()
  28. client := filer_pb.NewSeaweedFilerClient(grpcConnection)
  29. return fn(client)
  30. }