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.

40 lines
1.1 KiB

4 years ago
4 years ago
  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, dirPath, "", func(pbEntry *filer_pb.Entry, isLast bool) error {
  15. entry := filer.FromPbEntry(string(dirPath), pbEntry)
  16. if err := mc.doInsertEntry(context.Background(), entry); err != nil {
  17. glog.V(0).Infof("read %s: %v", entry.FullPath, err)
  18. return err
  19. }
  20. if entry.IsDirectory() {
  21. childDirectories = append(childDirectories, entry.Name())
  22. }
  23. return nil
  24. })
  25. return err
  26. })
  27. if err != nil {
  28. err = fmt.Errorf("list %s: %v", dirPath, err)
  29. }
  30. return
  31. })
  32. }