meta_cache_init.go 999 B

1234567891011121314151617181920212223242526272829303132333435
  1. package meta_cache
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/filer2"
  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) {
  11. mc.visitedBoundary.EnsureVisited(dirPath, func(path util.FullPath) (childDirectories []string, err error) {
  12. glog.V(4).Infof("ReadDirAllEntries %s ...", path)
  13. err = filer_pb.ReadDirAllEntries(client, dirPath, "", func(pbEntry *filer_pb.Entry, isLast bool) error {
  14. entry := filer2.FromPbEntry(string(dirPath), pbEntry)
  15. if err := mc.InsertEntry(context.Background(), entry); err != nil {
  16. glog.V(0).Infof("read %s: %v", entry.FullPath, err)
  17. return err
  18. }
  19. if entry.IsDirectory() {
  20. childDirectories = append(childDirectories, entry.Name())
  21. }
  22. return nil
  23. })
  24. if err != nil {
  25. err = fmt.Errorf("list %s: %v", dirPath, err)
  26. }
  27. return
  28. })
  29. }