Skip to content

Commit 44ffcea

Browse files
authored
Dir cached nearby check for client (#35)
* add method to check if children are cached nearby * continue and logs * remove debug log * better dir check
1 parent d01d5eb commit 44ffcea

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pkg/client.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,36 @@ func (c *BlobCacheClient) IsPathCachedNearby(ctx context.Context, path string) b
598598

599599
return c.IsCachedNearby(ctx, metadata.Hash)
600600
}
601+
602+
func (c *BlobCacheClient) IsDirCachedNearby(ctx context.Context, path string) bool {
603+
metadata, err := c.metadata.GetFsNode(ctx, GenerateFsID(path))
604+
if err != nil {
605+
Logger.Errorf("error getting fs node: %v, path: %s", err, path)
606+
return false
607+
}
608+
609+
return c.childrenCachedNearby(ctx, metadata.ID)
610+
}
611+
612+
func (c *BlobCacheClient) childrenCachedNearby(ctx context.Context, id string) bool {
613+
children, err := c.metadata.GetFsNodeChildren(ctx, id)
614+
if err != nil {
615+
Logger.Errorf("error getting fs node children: %v, id: %s", err, id)
616+
return false
617+
}
618+
619+
for _, child := range children {
620+
if (child.Mode & fuse.S_IFDIR) != 0 {
621+
if !c.childrenCachedNearby(ctx, child.ID) {
622+
return false
623+
}
624+
continue
625+
}
626+
627+
if !c.IsCachedNearby(ctx, child.Hash) {
628+
return false
629+
}
630+
}
631+
632+
return true
633+
}

0 commit comments

Comments
 (0)