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.

62 lines
1.5 KiB

  1. package filesys
  2. import (
  3. "bazil.org/fuse/fs"
  4. "bazil.org/fuse"
  5. "context"
  6. "os"
  7. "fmt"
  8. "path"
  9. "github.com/chrislusf/seaweedfs/weed/filer"
  10. )
  11. type Dir struct {
  12. Path string
  13. wfs *WFS
  14. }
  15. func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error {
  16. attr.Mode = os.ModeDir | 0555
  17. return nil
  18. }
  19. func (dir *Dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
  20. if entry, err := filer.LookupDirectoryEntry(dir.wfs.filer, dir.Path, name); err == nil {
  21. if !entry.Found {
  22. return nil, fuse.ENOENT
  23. }
  24. if entry.FileId != "" {
  25. return &File{FileId: filer.FileId(entry.FileId), Name: name, wfs: dir.wfs}, nil
  26. } else {
  27. return &Dir{Path: path.Join(dir.Path, name), wfs: dir.wfs}, nil
  28. }
  29. }
  30. return nil, fuse.ENOENT
  31. }
  32. func (dir *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
  33. var ret []fuse.Dirent
  34. if dirs, e := filer.ListDirectories(dir.wfs.filer, dir.Path); e == nil {
  35. for _, d := range dirs.Directories {
  36. dirent := fuse.Dirent{Name: string(d), Type: fuse.DT_Dir}
  37. ret = append(ret, dirent)
  38. }
  39. }
  40. if files, e := filer.ListFiles(dir.wfs.filer, dir.Path, ""); e == nil {
  41. for _, f := range files.Files {
  42. dirent := fuse.Dirent{Name: f.Name, Type: fuse.DT_File}
  43. ret = append(ret, dirent)
  44. }
  45. }
  46. return ret, nil
  47. }
  48. func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
  49. name := path.Join(dir.Path, req.Name)
  50. err := filer.DeleteDirectoryOrFile(dir.wfs.filer, name, req.Dir)
  51. if err != nil {
  52. fmt.Printf("Delete file %s [ERROR] %s\n", name, err)
  53. }
  54. return err
  55. }