diff options
author | Yue Gan <yueg@google.com> | 2016-09-19 09:42:40 +0000 |
---|---|---|
committer | Laszlo Csomor <laszlocsomor@google.com> | 2016-09-19 13:02:15 +0000 |
commit | 2f4d17a2fa632b05fcbeb8db5d6eb46af8ec341c (patch) | |
tree | 61966bda77c8e8e5b039adddaa9c1336251584fb /src/main/java/com/google/devtools/build/lib/sandbox | |
parent | 96d396badb3a0d8caab35aa4bb181cf88700ab79 (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.java | 11 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/sandbox/SymlinkedExecRoot.java | 14 |
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); + } } } } |