Search in sources :

Example 1 with Dirent

use of build.buildfarm.common.io.Dirent in project bazel-buildfarm by bazelbuild.

the class CFCExecFileSystem method start.

@SuppressWarnings("ConstantConditions")
@Override
public void start(Consumer<List<Digest>> onDigests, boolean skipLoad) throws IOException, InterruptedException {
    List<Dirent> dirents = null;
    try {
        dirents = readdir(root, /* followSymlinks= */
        false, Files.getFileStore(root));
    } catch (IOException e) {
        logger.log(Level.SEVERE, "error reading directory " + root.toString(), e);
    }
    ImmutableList.Builder<ListenableFuture<Void>> removeDirectoryFutures = ImmutableList.builder();
    // only valid path under root is cache
    for (Dirent dirent : dirents) {
        String name = dirent.getName();
        Path child = root.resolve(name);
        if (!child.equals(fileCache.getRoot())) {
            removeDirectoryFutures.add(Directories.remove(root.resolve(name), removeDirectoryService));
        }
    }
    ImmutableList.Builder<Digest> blobDigests = ImmutableList.builder();
    fileCache.start(digest -> {
        synchronized (blobDigests) {
            blobDigests.add(digest);
        }
    }, removeDirectoryService, skipLoad);
    onDigests.accept(blobDigests.build());
    getInterruptiblyOrIOException(allAsList(removeDirectoryFutures.build()));
}
Also used : Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) ImmutableList(com.google.common.collect.ImmutableList) Dirent(build.buildfarm.common.io.Dirent) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Utils.getInterruptiblyOrIOException(build.buildfarm.common.io.Utils.getInterruptiblyOrIOException) IOException(java.io.IOException)

Example 2 with Dirent

use of build.buildfarm.common.io.Dirent in project bazel-buildfarm by bazelbuild.

the class UploadManifest method computeDirectory.

private Directory computeDirectory(Path path, Tree.Builder tree) throws IllegalStateException, IOException {
    Directory.Builder b = Directory.newBuilder();
    List<Dirent> sortedDirent = readdir(path, /* followSymlinks= */
    false, fileStore);
    sortedDirent.sort(Comparator.comparing(Dirent::getName));
    for (Dirent dirent : sortedDirent) {
        String name = dirent.getName();
        Path child = path.resolve(name);
        if (dirent.getType() == Dirent.Type.DIRECTORY) {
            Directory dir = computeDirectory(child, tree);
            b.addDirectoriesBuilder().setName(name).setDigest(digestUtil.compute(dir));
            tree.addChildren(dir);
        } else if (dirent.getType() == Dirent.Type.FILE || (dirent.getType() == Dirent.Type.SYMLINK && allowSymlinks)) {
            Digest digest = digestUtil.compute(child);
            b.addFilesBuilder().setName(name).setDigest(digest).setIsExecutable(Files.isExecutable(child));
            digestToFile.put(digest, child);
        } else {
            illegalOutput(child);
        }
    }
    return b.build();
}
Also used : Path(java.nio.file.Path) Digest(build.bazel.remote.execution.v2.Digest) Dirent(build.buildfarm.common.io.Dirent) ByteString(com.google.protobuf.ByteString) Directory(build.bazel.remote.execution.v2.Directory)

Aggregations

Digest (build.bazel.remote.execution.v2.Digest)2 Dirent (build.buildfarm.common.io.Dirent)2 Path (java.nio.file.Path)2 Directory (build.bazel.remote.execution.v2.Directory)1 Utils.getInterruptiblyOrIOException (build.buildfarm.common.io.Utils.getInterruptiblyOrIOException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1