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.

67 lines
1.5 KiB

  1. package meta_cache
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/filer"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  8. "github.com/chrislusf/seaweedfs/weed/util"
  9. )
  10. func EnsureVisited(mc *MetaCache, client filer_pb.FilerClient, dirPath util.FullPath) error {
  11. for {
  12. // the directory children are already cached
  13. // so no need for this and upper directories
  14. if mc.isCachedFn(dirPath) {
  15. return nil
  16. }
  17. if err := doEnsureVisited(mc, client, dirPath); err != nil {
  18. return err
  19. }
  20. // continue to parent directory
  21. if dirPath != "/" {
  22. parent, _ := dirPath.DirAndName()
  23. dirPath = util.FullPath(parent)
  24. } else {
  25. break
  26. }
  27. }
  28. return nil
  29. }
  30. func doEnsureVisited(mc *MetaCache, client filer_pb.FilerClient, path util.FullPath) error {
  31. glog.V(4).Infof("ReadDirAllEntries %s ...", path)
  32. err := util.Retry("ReadDirAllEntries", func() error {
  33. return filer_pb.ReadDirAllEntries(client, path, "", func(pbEntry *filer_pb.Entry, isLast bool) error {
  34. entry := filer.FromPbEntry(string(path), pbEntry)
  35. if IsHiddenSystemEntry(string(path), entry.Name()) {
  36. return nil
  37. }
  38. if err := mc.doInsertEntry(context.Background(), entry); err != nil {
  39. glog.V(0).Infof("read %s: %v", entry.FullPath, err)
  40. return err
  41. }
  42. return nil
  43. })
  44. })
  45. if err != nil {
  46. err = fmt.Errorf("list %s: %v", path, err)
  47. }
  48. mc.markCachedFn(path)
  49. return err
  50. }
  51. func IsHiddenSystemEntry(dir, name string) bool {
  52. return dir == "/" && (name == "topics" || name == "etc")
  53. }