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.

47 lines
1.4 KiB

  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 InitMetaCache(mc *MetaCache, client filer_pb.FilerClient, path string) error {
  11. return nil
  12. glog.V(0).Infof("synchronizing meta data ...")
  13. filer_pb.TraverseBfs(client, util.FullPath(path), func(parentPath util.FullPath, pbEntry *filer_pb.Entry) {
  14. entry := filer2.FromPbEntry(string(parentPath), pbEntry)
  15. if err := mc.InsertEntry(context.Background(), entry); err != nil {
  16. glog.V(0).Infof("read %s: %v", entry.FullPath, err)
  17. }
  18. })
  19. return nil
  20. }
  21. func EnsureVisited(mc *MetaCache, client filer_pb.FilerClient, dirPath util.FullPath) {
  22. mc.visitedBoundary.EnsureVisited(dirPath, func(path util.FullPath) (childDirectories []string, err error) {
  23. glog.V(2).Infof("ReadDirAllEntries %s ...", path)
  24. err = filer_pb.ReadDirAllEntries(client, dirPath, "", func(pbEntry *filer_pb.Entry, isLast bool) error {
  25. entry := filer2.FromPbEntry(string(dirPath), pbEntry)
  26. if err := mc.InsertEntry(context.Background(), entry); err != nil {
  27. glog.V(0).Infof("read %s: %v", entry.FullPath, err)
  28. return err
  29. }
  30. if entry.IsDirectory() {
  31. childDirectories = append(childDirectories, entry.Name())
  32. }
  33. return nil
  34. })
  35. if err != nil {
  36. err = fmt.Errorf("list %s: %v", dirPath, err)
  37. }
  38. return
  39. })
  40. }