Skip to content

Commit fc44891

Browse files
committed
remote: fix unexpected IO error (not a directory)
Fixes bazelbuild#4751
1 parent ce91f76 commit fc44891

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
2525
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
2626
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
27+
import com.google.devtools.build.lib.vfs.Path;
2728
import com.google.devtools.build.lib.vfs.PathFragment;
2829
import java.util.ArrayList;
2930
import java.util.Collection;
@@ -218,4 +219,16 @@ public static List<ActionInput> expandArtifacts(Iterable<? extends ActionInput>
218219
public static Iterable<String> toExecPaths(Iterable<? extends ActionInput> artifacts) {
219220
return Iterables.transform(artifacts, EXEC_PATH_STRING_FORMATTER);
220221
}
222+
223+
/**
224+
* Returns the {@link Path} for an {@link ActionInput}.
225+
*/
226+
public static Path toPath(ActionInput input, Path execRoot) {
227+
Preconditions.checkNotNull(input, "input");
228+
Preconditions.checkNotNull(execRoot, "execRoot");
229+
230+
return (input instanceof Artifact)
231+
? ((Artifact) input).getPath()
232+
: execRoot.getRelative(input.getExecPath());
233+
}
221234
}

src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.google.common.cache.Cache;
1717
import com.google.common.cache.CacheBuilder;
1818
import com.google.devtools.build.lib.actions.ActionInput;
19+
import com.google.devtools.build.lib.actions.ActionInputHelper;
1920
import com.google.devtools.build.lib.actions.Artifact;
2021
import com.google.devtools.build.lib.actions.DigestOfDirectoryException;
2122
import com.google.devtools.build.lib.actions.FileArtifactValue;
@@ -60,10 +61,7 @@ public FileArtifactValue getMetadata(ActionInput input) throws IOException {
6061
.get(
6162
input.getExecPathString(),
6263
() -> {
63-
Path path =
64-
(input instanceof Artifact)
65-
? ((Artifact) input).getPath()
66-
: execRoot.getRelative(input.getExecPath());
64+
Path path = ActionInputHelper.toPath(input, execRoot);
6765
try {
6866
FileArtifactValue metadata = FileArtifactValue.create(path);
6967
if (metadata.getType().isDirectory()) {

src/main/java/com/google/devtools/build/lib/remote/TreeNodeRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ private TreeNode buildParentNode(
340340
Preconditions.checkArgument(
341341
inputsStart == inputsEnd - 1, "Encountered two inputs with the same path.");
342342
ActionInput input = inputs.get(inputsStart);
343-
Path leafPath = execRoot.getRelative(input.getExecPathString());
343+
Path leafPath = ActionInputHelper.toPath(input, execRoot);
344344
if (!(input instanceof VirtualActionInput) && uploadSymlinks) {
345345
FileStatus stat = leafPath.stat(Symlinks.NOFOLLOW);
346346
if (stat.isSymbolicLink()) {
@@ -405,7 +405,7 @@ private synchronized Directory getOrComputeDirectory(TreeNode node) throws IOExc
405405
if (uploadSymlinks) {
406406
// We need to stat the input to check whether it is a symlink.
407407
// getInputMetadata only gives target metadata.
408-
Path inputPath = execRoot.getRelative(input.getExecPath());
408+
Path inputPath = ActionInputHelper.toPath(input, execRoot);
409409
FileStatus stat = inputPath.stat(Symlinks.NOFOLLOW);
410410
if (stat.isSymbolicLink()) {
411411
PathFragment target = inputPath.readSymbolicLink();

0 commit comments

Comments
 (0)