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.

44 lines
1.2 KiB

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