use of build.buildfarm.common.io.Directories in project bazel-buildfarm by bazelbuild.
the class CFCExecFileSystem method fetchInputs.
private Iterable<ListenableFuture<Void>> fetchInputs(Path path, Digest directoryDigest, Map<Digest, Directory> directoriesIndex, OutputDirectory outputDirectory, ImmutableList.Builder<String> inputFiles, ImmutableList.Builder<Digest> inputDirectories) throws IOException {
Directory directory = directoriesIndex.get(directoryDigest);
if (directory == null) {
// not quite IO...
throw new IOException("Directory " + DigestUtil.toString(directoryDigest) + " is not in directories index");
}
Iterable<ListenableFuture<Void>> downloads = directory.getFilesList().stream().map(fileNode -> put(path, fileNode, inputFiles)).collect(ImmutableList.toImmutableList());
downloads = concat(downloads, directory.getSymlinksList().stream().map(symlinkNode -> putSymlink(path, symlinkNode)).collect(ImmutableList.toImmutableList()));
for (DirectoryNode directoryNode : directory.getDirectoriesList()) {
Digest digest = directoryNode.getDigest();
String name = directoryNode.getName();
OutputDirectory childOutputDirectory = outputDirectory != null ? outputDirectory.getChild(name) : null;
Path dirPath = path.resolve(name);
if (childOutputDirectory != null || !linkInputDirectories) {
Files.createDirectories(dirPath);
downloads = concat(downloads, fetchInputs(dirPath, digest, directoriesIndex, childOutputDirectory, inputFiles, inputDirectories));
} else {
downloads = concat(downloads, ImmutableList.of(transform(linkDirectory(dirPath, digest, directoriesIndex), (result) -> {
// we saw null entries in the built immutable list without synchronization
synchronized (inputDirectories) {
inputDirectories.add(digest);
}
return null;
}, fetchService)));
}
if (Thread.currentThread().isInterrupted()) {
break;
}
}
return downloads;
}
Aggregations