| 104 | } |
| 105 | |
| 106 | func (s *metadataStore) list() ([]Metadata, error) { |
| 107 | ctxDirs, err := listRecursivelyMetadataDirs(s.root) |
| 108 | if err != nil { |
| 109 | if errors.Is(err, os.ErrNotExist) { |
| 110 | return nil, nil |
| 111 | } |
| 112 | return nil, err |
| 113 | } |
| 114 | res := make([]Metadata, 0, len(ctxDirs)) |
| 115 | for _, dir := range ctxDirs { |
| 116 | c, err := s.getByID(contextdir(dir)) |
| 117 | if err != nil { |
| 118 | if errors.Is(err, os.ErrNotExist) { |
| 119 | continue |
| 120 | } |
| 121 | return nil, fmt.Errorf("failed to read metadata: %w", err) |
| 122 | } |
| 123 | res = append(res, c) |
| 124 | } |
| 125 | sort.Slice(res, func(i, j int) bool { |
| 126 | return sortorder.NaturalLess(res[i].Name, res[j].Name) |
| 127 | }) |
| 128 | return res, nil |
| 129 | } |
| 130 | |
| 131 | func isContextDir(path string) bool { |
| 132 | s, err := os.Stat(filepath.Join(path, metaFile)) |