aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCache.java
diff options
context:
space:
mode:
authorGravatar buchgr <buchgr@google.com>2018-04-18 04:41:10 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-18 04:42:46 -0700
commitfa36d2f48965b127e8fd397348d16e991135bfb6 (patch)
treecfdce5e5301a5f93186478dc5ceaf0cbfffa01d8 /src/main/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCache.java
parentf083e7623cd03e20ed216117c5ea8c8b4ec61948 (diff)
Automated rollback of commit 4465dae23de989f1452e93d0a88ac2a289103dd9.
*** Reason for rollback *** The no-cache tag is not respected (see b/77857812) and thus this breaks remote caching for all projects with symlink outputs. *** Original change description *** Only allow regular files and directories spawn outputs to be uploaded to a remote cache. The remote cache protocol only knows about regular files and directories. Currently, during action output upload, symlinks are resolved into regular files. This means cached "executions" of an action may have different output file types than the original execution, which can be a footgun. This CL bans symlinks from cachable spawn outputs and fixes http... *** PiperOrigin-RevId: 193338629
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCache.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCache.java53
1 files changed, 15 insertions, 38 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCache.java b/src/main/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCache.java
index 3bd935ca63..be81ad6cfe 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCache.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCache.java
@@ -15,16 +15,13 @@ package com.google.devtools.build.lib.remote;
import com.google.devtools.build.lib.actions.EnvironmentalExecException;
import com.google.devtools.build.lib.actions.ExecException;
-import com.google.devtools.build.lib.actions.UserExecException;
import com.google.devtools.build.lib.concurrent.ThreadSafety;
import com.google.devtools.build.lib.remote.TreeNodeRepository.TreeNode;
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.util.io.FileOutErr;
import com.google.devtools.build.lib.vfs.Dirent;
-import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.Symlinks;
import com.google.devtools.remoteexecution.v1test.ActionResult;
import com.google.devtools.remoteexecution.v1test.Command;
import com.google.devtools.remoteexecution.v1test.Digest;
@@ -96,7 +93,7 @@ public abstract class AbstractRemoteActionCache implements AutoCloseable {
Collection<Path> files,
FileOutErr outErr,
boolean uploadAction)
- throws ExecException, IOException, InterruptedException;
+ throws IOException, InterruptedException;
/**
* Download a remote blob to a local destination.
@@ -256,9 +253,10 @@ public abstract class AbstractRemoteActionCache implements AutoCloseable {
}
}
- /** UploadManifest adds output metadata to a {@link ActionResult}. */
- static class UploadManifest {
- private final DigestUtil digestUtil;
+ /**
+ * The UploadManifest is used to mutualize upload between the RemoteActionCache implementations.
+ */
+ public class UploadManifest {
private final ActionResult.Builder result;
private final Path execRoot;
private final Map<Digest, Path> digestToFile;
@@ -268,8 +266,7 @@ public abstract class AbstractRemoteActionCache implements AutoCloseable {
* Create an UploadManifest from an ActionResult builder and an exec root. The ActionResult
* builder is populated through a call to {@link #addFile(Digest, Path)}.
*/
- public UploadManifest(DigestUtil digestUtil, ActionResult.Builder result, Path execRoot) {
- this.digestUtil = digestUtil;
+ public UploadManifest(ActionResult.Builder result, Path execRoot) {
this.result = result;
this.execRoot = execRoot;
@@ -278,31 +275,24 @@ public abstract class AbstractRemoteActionCache implements AutoCloseable {
}
/**
- * Add a collection of files or directories to the UploadManifest. Adding a directory has the
+ * Add a collection of files (and directories) to the UploadManifest. Adding a directory has the
* effect of 1) uploading a {@link Tree} protobuf message from which the whole structure of the
* directory, including the descendants, can be reconstructed and 2) uploading all the
* non-directory descendant files.
- *
- * <p>Attempting to a upload symlink results in a {@link
- * com.google.build.lib.actions.ExecException}, since cachable actions shouldn't emit symlinks.
*/
- public void addFiles(Collection<Path> files)
- throws ExecException, IOException, InterruptedException {
+ public void addFiles(Collection<Path> files) throws IOException, InterruptedException {
for (Path file : files) {
// TODO(ulfjack): Maybe pass in a SpawnResult here, add a list of output files to that, and
// rely on the local spawn runner to stat the files, instead of statting here.
- FileStatus stat = file.statIfFound(Symlinks.NOFOLLOW);
- if (stat == null) {
+ if (!file.exists()) {
// We ignore requested results that have not been generated by the action.
continue;
}
- if (stat.isDirectory()) {
+ if (file.isDirectory()) {
addDirectory(file);
- } else if (stat.isFile()) {
- Digest digest = digestUtil.compute(file, stat.getSize());
- addFile(digest, file);
} else {
- illegalOutput(file);
+ Digest digest = digestUtil.compute(file);
+ addFile(digest, file);
}
}
}
@@ -331,7 +321,7 @@ public abstract class AbstractRemoteActionCache implements AutoCloseable {
digestToFile.put(digest, file);
}
- private void addDirectory(Path dir) throws ExecException, IOException {
+ private void addDirectory(Path dir) throws IOException {
Tree.Builder tree = Tree.newBuilder();
Directory root = computeDirectory(dir, tree);
tree.setRoot(root);
@@ -350,8 +340,7 @@ public abstract class AbstractRemoteActionCache implements AutoCloseable {
digestToChunkers.put(chunker.digest(), chunker);
}
- private Directory computeDirectory(Path path, Tree.Builder tree)
- throws ExecException, IOException {
+ private Directory computeDirectory(Path path, Tree.Builder tree) throws IOException {
Directory.Builder b = Directory.newBuilder();
List<Dirent> sortedDirent = new ArrayList<>(path.readdir(TreeNodeRepository.SYMLINK_POLICY));
@@ -364,27 +353,15 @@ public abstract class AbstractRemoteActionCache implements AutoCloseable {
Directory dir = computeDirectory(child, tree);
b.addDirectoriesBuilder().setName(name).setDigest(digestUtil.compute(dir));
tree.addChildren(dir);
- } else if (dirent.getType() == Dirent.Type.FILE) {
+ } else {
Digest digest = digestUtil.compute(child);
b.addFilesBuilder().setName(name).setDigest(digest).setIsExecutable(child.isExecutable());
digestToFile.put(digest, child);
- } else {
- illegalOutput(child);
}
}
return b.build();
}
-
- private void illegalOutput(Path what) throws ExecException, IOException {
- String kind = what.isSymbolicLink() ? "symbolic link" : "special file";
- throw new UserExecException(
- String.format(
- "Output %s is a %s. Only regular files and directories may be "
- + "uploaded to a remote cache. "
- + "Change the file type or add the \"no-cache\" tag/execution requirement.",
- what.relativeTo(execRoot), kind));
- }
}
/** Release resources associated with the cache. The cache may not be used after calling this. */