From 73705e768d7b17e2022ad6b049451d962383601c Mon Sep 17 00:00:00 2001 From: Chi Wang Date: Wed, 13 Jan 2021 14:58:41 +0800 Subject: [PATCH] remote: set executable bit of an input file based on its real value. The "always mark" was introduced by 3e3b71ae038bc9ac90456f93697c640ab9ed8a55 which was a workaround for #4751. However, that issue was then fixed by fc448916ae04d22743fa4ae44d954f9faedb4f3a. There is no reason to keep the workaround which is causing other issues e.g. #12818. --- .../lib/remote/merkletree/DirectoryTree.java | 56 ++++++++++--------- .../lib/remote/merkletree/MerkleTree.java | 6 +- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTree.java b/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTree.java index 40572bd35f32bb..62bcf485a9c919 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTree.java +++ b/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTree.java @@ -20,6 +20,8 @@ import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.protobuf.ByteString; + +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -34,7 +36,7 @@ final class DirectoryTree { interface Visitor { - void visitDirectory(PathFragment dirname, List files, List dirs); + void visitDirectory(PathFragment dirname, List files, List dirs) throws IOException; } abstract static class Node implements Comparable { @@ -165,15 +167,15 @@ boolean isEmpty() { } /** - * Traverses the {@link ActionInputsTree} in a depth first search manner. The children are visited + * Traverses the {@link DirectoryTree} in a depth first search manner. The children are visited * in lexographical order. */ - void visit(Visitor visitor) { + void visit(Visitor visitor) throws IOException { Preconditions.checkNotNull(visitor, "visitor"); visit(visitor, PathFragment.EMPTY_FRAGMENT); } - private void visit(Visitor visitor, PathFragment dirname) { + private void visit(Visitor visitor, PathFragment dirname) throws IOException { DirectoryNode dir = tree.get(dirname); if (dir == null) { return; @@ -198,30 +200,34 @@ private void visit(Visitor visitor, PathFragment dirname) { @Override public String toString() { Map m = new HashMap<>(); - visit( - (dirname, files, dirs) -> { - int depth = dirname.segmentCount() - 1; - StringBuilder sb = new StringBuilder(); - - if (!dirname.equals(PathFragment.EMPTY_FRAGMENT)) { - sb.append(Strings.repeat(" ", depth)); - sb.append(dirname.getBaseName()); - sb.append("\n"); - } - if (!files.isEmpty()) { - for (FileNode file : files) { - sb.append(Strings.repeat(" ", depth + 1)); - sb.append(formatFile(file)); + try { + visit( + (dirname, files, dirs) -> { + int depth = dirname.segmentCount() - 1; + StringBuilder sb = new StringBuilder(); + + if (!dirname.equals(PathFragment.EMPTY_FRAGMENT)) { + sb.append(Strings.repeat(" ", depth)); + sb.append(dirname.getBaseName()); sb.append("\n"); } - } - if (!dirs.isEmpty()) { - for (DirectoryNode dir : dirs) { - sb.append(m.remove(dirname.getRelative(dir.getPathSegment()))); + if (!files.isEmpty()) { + for (FileNode file : files) { + sb.append(Strings.repeat(" ", depth + 1)); + sb.append(formatFile(file)); + sb.append("\n"); + } + } + if (!dirs.isEmpty()) { + for (DirectoryNode dir : dirs) { + sb.append(m.remove(dirname.getRelative(dir.getPathSegment()))); + } } - } - m.put(dirname, sb); - }); + m.put(dirname, sb); + }); + } catch (IOException e) { + return e.toString(); + } return m.get(PathFragment.EMPTY_FRAGMENT).toString(); } diff --git a/src/main/java/com/google/devtools/build/lib/remote/merkletree/MerkleTree.java b/src/main/java/com/google/devtools/build/lib/remote/merkletree/MerkleTree.java index 7fac053ae32aa4..a52d56ec7bf2fd 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/merkletree/MerkleTree.java +++ b/src/main/java/com/google/devtools/build/lib/remote/merkletree/MerkleTree.java @@ -157,7 +157,7 @@ public static MerkleTree build(SortedMap inputFiles, DigestU } } - private static MerkleTree build(DirectoryTree tree, DigestUtil digestUtil) { + private static MerkleTree build(DirectoryTree tree, DigestUtil digestUtil) throws IOException { Preconditions.checkNotNull(tree); if (tree.isEmpty()) { return new MerkleTree( @@ -194,11 +194,11 @@ private static MerkleTree build(DirectoryTree tree, DigestUtil digestUtil) { digestDirectoryMap, digestPathMap, rootDigest, tree.numFiles(), inputBytes.get()); } - private static FileNode buildProto(DirectoryTree.FileNode file) { + private static FileNode buildProto(DirectoryTree.FileNode file) throws IOException { return FileNode.newBuilder() .setName(file.getPathSegment()) .setDigest(file.getDigest()) - .setIsExecutable(true) + .setIsExecutable(file.getPath().isExecutable()) .build(); }