meta_cache_init.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. return mc.visitedBoundary.EnsureVisited(dirPath, func(path util.FullPath) (childDirectories []string, err error) {
  12. glog.V(4).Infof("ReadDirAllEntries %s ...", path)
  13. util.Retry("ReadDirAllEntries", func() error {
  14. err = filer_pb.ReadDirAllEntries(client, path, "", func(pbEntry *filer_pb.Entry, isLast bool) error {
  15. entry := filer.FromPbEntry(string(path), pbEntry)
  16. if IsHiddenSystemEntry(string(path), entry.Name()) {
  17. return nil
  18. }
  19. if err := mc.doInsertEntry(context.Background(), entry); err != nil {
  20. glog.V(0).Infof("read %s: %v", entry.FullPath, err)
  21. return err
  22. }
  23. if entry.IsDirectory() {
  24. childDirectories = append(childDirectories, entry.Name())
  25. }
  26. return nil
  27. })
  28. return err
  29. })
  30. if err != nil {
  31. err = fmt.Errorf("list %s: %v", path, err)
  32. }
  33. return
  34. })
  35. }
  36. func IsHiddenSystemEntry(dir, name string) bool {
  37. return dir == "/" && (name == "topics" || name == "etc")
  38. }