MCPcopy
hub / github.com/perkeep/perkeep / populate

Method populate

pkg/fs/rover.go:253–300  ·  view source on GitHub ↗

populate hits the blobstore to populate map of child nodes.

(ctx context.Context)

Source from the content-addressed store, hash-verified

251
252// populate hits the blobstore to populate map of child nodes.
253func (n *roFileVersionsDir) populate(ctx context.Context) error {
254 n.mu.Lock()
255 defer n.mu.Unlock()
256
257 // Things never change here, so if we've ever populated, we're
258 // populated.
259 if n.children != nil {
260 return nil
261 }
262
263 Logger.Printf("roFileVersionsDir.populate(%q)", n.fullPath())
264 res, err := n.fs.client.GetClaims(ctx, &search.ClaimsRequest{Permanode: n.permanode, AttrFilter: "camliContent"})
265 if err != nil {
266 return fmt.Errorf("error while getting claims: %w", err)
267 }
268
269 n.children = make(map[string]roFileOrDir)
270 for _, cl := range res.Claims {
271 pn, ok := blob.Parse(cl.Value)
272 if !ok {
273 return errors.New("invalid blobref")
274 }
275 res, err := n.fs.client.Describe(ctx, &search.DescribeRequest{
276 BlobRef: pn, // this is camliContent
277 Depth: 1,
278 At: cl.Date,
279 })
280 if err != nil {
281 return fmt.Errorf("blobref not described: %w", err)
282 }
283 db := res.Meta[cl.Value]
284 if db == nil {
285 return errors.New("blobref not described")
286 }
287 name := cl.Date.String()
288 n.children[name] = &roFileVersion{
289 fs: n.fs,
290 permanode: n.permanode,
291 parent: n,
292 name: name,
293 content: db.BlobRef,
294 size: db.File.Size,
295 mtime: cl.Date.Time(),
296 }
297
298 }
299 return nil
300}
301
302func (n *roFileVersionsDir) ReadDir(ctx context.Context) ([]fuse.Dirent, error) {
303 if err := n.populate(ctx); err != nil {

Callers 2

ReadDirMethod · 0.95
LookupMethod · 0.95

Calls 8

fullPathMethod · 0.95
ParseFunction · 0.92
LockMethod · 0.80
UnlockMethod · 0.80
PrintfMethod · 0.80
DescribeMethod · 0.65
GetClaimsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected