aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/sandbox
diff options
context:
space:
mode:
authorGravatar Yue Gan <yueg@google.com>2016-09-19 09:42:40 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2016-09-19 13:02:15 +0000
commit2f4d17a2fa632b05fcbeb8db5d6eb46af8ec341c (patch)
tree61966bda77c8e8e5b039adddaa9c1336251584fb /src/main/java/com/google/devtools/build/lib/sandbox
parent96d396badb3a0d8caab35aa4bb181cf88700ab79 (diff)
Also copy directories as output for sandbox.
-- MOS_MIGRATED_REVID=133564429
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/sandbox')
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/HardlinkedExecRoot.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/SymlinkedExecRoot.java14
2 files changed, 18 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/HardlinkedExecRoot.java b/src/main/java/com/google/devtools/build/lib/sandbox/HardlinkedExecRoot.java
index 0ce8c76bce..7ddb401bfd 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/HardlinkedExecRoot.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/HardlinkedExecRoot.java
@@ -124,7 +124,6 @@ public class HardlinkedExecRoot implements SandboxExecRoot {
}
}
- // TODO(yueg): import unix.FilesystemUtils and use FilesystemUtils.createHardLink() instead
private void createHardLink(Path target, Path source) throws IOException {
java.nio.file.Path targetNio = java.nio.file.Paths.get(target.toString());
java.nio.file.Path sourceNio = java.nio.file.Paths.get(source.toString());
@@ -153,9 +152,17 @@ public class HardlinkedExecRoot implements SandboxExecRoot {
public void copyOutputs(Path execRoot, Collection<PathFragment> outputs) throws IOException {
for (PathFragment output : outputs) {
Path source = sandboxExecRoot.getRelative(output);
+ Path target = execRoot.getRelative(output);
if (source.isFile() || source.isSymbolicLink()) {
- Path target = execRoot.getRelative(output);
Files.move(source.getPathFile(), target.getPathFile());
+ } else if (source.isDirectory()) {
+ try {
+ source.renameTo(target);
+ } catch (IOException e) {
+ // Failed to move directory directly, thus move it recursively.
+ target.createDirectory();
+ FileSystemUtils.moveTreesBelow(source, target);
+ }
}
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SymlinkedExecRoot.java b/src/main/java/com/google/devtools/build/lib/sandbox/SymlinkedExecRoot.java
index de0f31f46e..9efe7fcb45 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/SymlinkedExecRoot.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/SymlinkedExecRoot.java
@@ -100,15 +100,19 @@ final class SymlinkedExecRoot implements SandboxExecRoot {
/** Moves all {@code outputs} to {@code execRoot}. */
@Override
public void copyOutputs(Path execRoot, Collection<PathFragment> outputs) throws IOException {
- Set<Path> createdDirs = new HashSet<>();
for (PathFragment output : outputs) {
Path source = sandboxExecRoot.getRelative(output);
+ Path target = execRoot.getRelative(output);
if (source.isFile() || source.isSymbolicLink()) {
- FileSystemUtils.createDirectoryAndParentsWithCache(
- createdDirs, execRoot.getRelative(output.getParentDirectory()));
-
- Path target = execRoot.getRelative(output);
Files.move(source.getPathFile(), target.getPathFile());
+ } else if (source.isDirectory()) {
+ try {
+ source.renameTo(target);
+ } catch (IOException e) {
+ // Failed to move directory directly, thus move it recursively.
+ target.createDirectory();
+ FileSystemUtils.moveTreesBelow(source, target);
+ }
}
}
}