use of com.facebook.buck.distributed.thrift.PathInfo in project buck by facebook.
the class DistBuildService method uploadBuckDotFiles.
public ListenableFuture<Void> uploadBuckDotFiles(final StampedeId id, final ProjectFilesystem filesystem, FileHashCache fileHashCache, ListeningExecutorService executorService) throws IOException {
ListenableFuture<Pair<List<FileInfo>, List<PathInfo>>> filesFuture = executorService.submit(() -> {
List<Path> buckDotFilesExceptConfig = Lists.newArrayList();
for (Path path : filesystem.getDirectoryContents(filesystem.getRootPath())) {
String fileName = path.getFileName().toString();
if (!filesystem.isDirectory(path) && !filesystem.isSymLink(path) && fileName.startsWith(".") && fileName.contains("buck") && !fileName.startsWith(".buckconfig")) {
buckDotFilesExceptConfig.add(path);
}
}
List<FileInfo> fileEntriesToUpload = new LinkedList<>();
List<PathInfo> pathEntriesToUpload = new LinkedList<>();
for (Path path : buckDotFilesExceptConfig) {
FileInfo fileInfoObject = new FileInfo();
fileInfoObject.setContent(filesystem.readFileIfItExists(path).get().getBytes());
fileInfoObject.setContentHash(fileHashCache.get(path.toAbsolutePath()).toString());
fileEntriesToUpload.add(fileInfoObject);
PathInfo pathInfoObject = new PathInfo();
pathInfoObject.setPath(path.toString());
pathInfoObject.setContentHash(fileHashCache.get(path.toAbsolutePath()).toString());
pathEntriesToUpload.add(pathInfoObject);
}
return new Pair<>(fileEntriesToUpload, pathEntriesToUpload);
});
ListenableFuture<Void> setFilesFuture = Futures.transformAsync(filesFuture, filesAndPaths -> {
setBuckDotFiles(id, filesAndPaths.getSecond());
return Futures.immediateFuture(null);
}, executorService);
ListenableFuture<Void> uploadFilesFuture = Futures.transformAsync(filesFuture, filesAndPaths -> {
uploadMissingFilesFromList(filesAndPaths.getFirst(), executorService);
return Futures.immediateFuture(null);
}, executorService);
return Futures.transform(Futures.allAsList(ImmutableList.of(setFilesFuture, uploadFilesFuture)), new Function<List<Void>, Void>() {
@Nullable
@Override
public Void apply(@Nullable List<Void> input) {
return null;
}
});
}
Aggregations