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.

74 lines
1.6 KiB

7 years ago
7 years ago
  1. package filesys
  2. import (
  3. "context"
  4. "fmt"
  5. "bazil.org/fuse"
  6. "github.com/chrislusf/seaweedfs/weed/filer"
  7. "bazil.org/fuse/fs"
  8. "github.com/chrislusf/seaweedfs/weed/glog"
  9. )
  10. var _ = fs.Node(&File{})
  11. // var _ = fs.NodeOpener(&File{})
  12. // var _ = fs.NodeFsyncer(&File{})
  13. var _ = fs.Handle(&File{})
  14. var _ = fs.HandleReadAller(&File{})
  15. // var _ = fs.HandleReader(&File{})
  16. var _ = fs.HandleWriter(&File{})
  17. type File struct {
  18. FileId filer.FileId
  19. Name string
  20. wfs *WFS
  21. }
  22. func (file *File) Attr(context context.Context, attr *fuse.Attr) error {
  23. attr.Mode = 0444
  24. return file.wfs.withFilerClient(func(client filer.SeaweedFilerClient) error {
  25. request := &filer.GetFileAttributesRequest{
  26. Name: file.Name,
  27. ParentDir: "", //TODO add parent folder
  28. FileId: string(file.FileId),
  29. }
  30. glog.V(1).Infof("read file size: %v", request)
  31. resp, err := client.GetFileAttributes(context, request)
  32. if err != nil {
  33. return err
  34. }
  35. attr.Size = resp.Attributes.FileSize
  36. return nil
  37. })
  38. }
  39. func (file *File) ReadAll(ctx context.Context) (content []byte, err error) {
  40. err = file.wfs.withFilerClient(func(client filer.SeaweedFilerClient) error {
  41. request := &filer.GetFileContentRequest{
  42. FileId: string(file.FileId),
  43. }
  44. glog.V(1).Infof("read file content: %v", request)
  45. resp, err := client.GetFileContent(ctx, request)
  46. if err != nil {
  47. return err
  48. }
  49. content = resp.Content
  50. return nil
  51. })
  52. return content, err
  53. }
  54. func (file *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
  55. fmt.Printf("write file %+v\n", req)
  56. return nil
  57. }