Skip to content

Commit

Permalink
remote: fix download of output directories
Browse files Browse the repository at this point in the history
Fix a bug where Bazel would crash if two Directory protos had the same
hash.

RELNOTES: Remote Caching and Execution support output directories.
PiperOrigin-RevId: 179731040
  • Loading branch information
buchgr authored and Copybara-Service committed Dec 20, 2017
1 parent ac2cd35 commit 243c0a8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ private void downloadDirectory(Path path, Directory dir, Map<Digest, Directory>
+ "not found");
}
downloadDirectory(childPath, childDir, childrenMap);

// Prevent reuse.
childrenMap.remove(childDigest);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,49 @@ public void testDownloadDirectoryNested() throws Exception {
assertThat(execRoot.getRelative("a/bar/wobble/qux").isExecutable()).isFalse();
}

@Test
public void testDownloadDirectoriesWithSameHash() throws Exception {
// Test that downloading an output directory works when two Directory
// protos have the same hash i.e. because they have the same name and contents or are empty.

/*
* /bar/foo/file
* /foo/file
*/
Digest fileDigest = DIGEST_UTIL.computeAsUtf8("file");
FileNode file =
FileNode.newBuilder().setName("file").setDigest(fileDigest).build();
Directory fooDir = Directory.newBuilder().addFiles(file).build();
Digest fooDigest = DIGEST_UTIL.compute(fooDir);
DirectoryNode fooDirNode =
DirectoryNode.newBuilder().setName("foo").setDigest(fooDigest).build();
Directory barDir = Directory.newBuilder().addDirectories(fooDirNode).build();
Digest barDigest = DIGEST_UTIL.compute(barDir);
DirectoryNode barDirNode =
DirectoryNode.newBuilder().setName("bar").setDigest(barDigest).build();
Directory rootDir =
Directory.newBuilder().addDirectories(fooDirNode).addDirectories(barDirNode).build();

Tree tree = Tree.newBuilder()
.setRoot(rootDir)
.addChildren(barDir)
.addChildren(fooDir)
.addChildren(fooDir)
.build();
Digest treeDigest = DIGEST_UTIL.compute(tree);

final ConcurrentMap<String, byte[]> map = new ConcurrentHashMap<>();
map.put(fileDigest.getHash(), "file".getBytes(Charsets.UTF_8));
map.put(treeDigest.getHash(), tree.toByteArray());
SimpleBlobStoreActionCache client = newClient(map);
ActionResult.Builder result = ActionResult.newBuilder();
result.addOutputDirectoriesBuilder().setPath("a/").setTreeDigest(treeDigest);
client.download(result.build(), execRoot, null);

assertThat(DIGEST_UTIL.compute(execRoot.getRelative("a/bar/foo/file"))).isEqualTo(fileDigest);
assertThat(DIGEST_UTIL.compute(execRoot.getRelative("a/foo/file"))).isEqualTo(fileDigest);
}

@Test
public void testUploadBlob() throws Exception {
final Digest digest = DIGEST_UTIL.computeAsUtf8("abcdefg");
Expand Down

0 comments on commit 243c0a8

Please sign in to comment.