Skip to content

Commit

Permalink
Fix GetTree fakes (#539)
Browse files Browse the repository at this point in the history
`GetTree` was iterating over the `FileNode`s and trying to parse the blob as a `Directory`, it should only need to iterate over the `DirectoryNode`s. It was also adding the `Directory` to the `res`ult list when adding and removing the `Directory` from the queue, doubling the output.

The output now matches the RBE server, at least for a simple example.
  • Loading branch information
danw authored Mar 7, 2024
1 parent a108ad8 commit 0019a74
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions go/pkg/fakes/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,28 +542,13 @@ func (f *CAS) GetTree(req *repb.GetTreeRequest, stream regrpc.ContentAddressable
rootDir := &repb.Directory{}
proto.Unmarshal(blob, rootDir)

res := []*repb.Directory{rootDir}
res := []*repb.Directory{}
queue := []*repb.Directory{rootDir}
for len(queue) > 0 {
ele := queue[0]
res = append(res, ele)
queue = queue[1:]

for _, inpFile := range ele.GetFiles() {
fd, err := digest.NewFromProto(inpFile.GetDigest())
if err != nil {
return fmt.Errorf("unable to parse file digest %v", inpFile.GetDigest())
}
blob, ok := f.Get(fd)
if !ok {
return fmt.Errorf("file digest %v not found", fd)
}
dir := &repb.Directory{}
proto.Unmarshal(blob, dir)
queue = append(queue, dir)
res = append(res, dir)
}

for _, dir := range ele.GetDirectories() {
fd, err := digest.NewFromProto(dir.GetDigest())
if err != nil {
Expand All @@ -576,7 +561,6 @@ func (f *CAS) GetTree(req *repb.GetTreeRequest, stream regrpc.ContentAddressable
directory := &repb.Directory{}
proto.Unmarshal(blob, directory)
queue = append(queue, directory)
res = append(res, directory)
}
}

Expand Down

0 comments on commit 0019a74

Please sign in to comment.