diff options
author | Kush Chakraborty <kush@google.com> | 2016-11-23 16:25:32 +0000 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2016-11-23 16:46:08 +0000 |
commit | f36b4061b4c3c731bd90e34b9fe7648a50542d8c (patch) | |
tree | 85317c089b44d4fcb490f9db40a213646fd33df0 /src/main/java/com/google/devtools/build | |
parent | ad13a9c08d4702d9bc4cfcd8dc433995d34350d0 (diff) |
Properly handle bazel's output deletion within a write-protected directory.
Currently, we fail in deleting outputs from a previous invocation in a write-protected directory.
This change retries deleting the outputs, after making the parent write-protected directory writable again.
--
MOS_MIGRATED_REVID=140035023
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java b/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java index dd4dc97169..dc1857826b 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java +++ b/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java @@ -370,11 +370,22 @@ public abstract class AbstractAction implements Action, SkylarkValue { // Optimize for the common case: output artifacts are files. path.delete(); } catch (IOException e) { - // Only try to recursively delete a directory if the output root is known. This is just a - // sanity check so that we do not start deleting random files on disk. - // TODO(bazel-team): Strengthen this test by making sure that the output is part of the - // output tree. - if (path.isDirectory(Symlinks.NOFOLLOW) && output.getRoot() != null) { + // Handle a couple of scenarios where the output can still be deleted, but make sure we're not + // deleting random files on the filesystem. + if (output.getRoot() == null) { + throw e; + } + String outputRootDir = output.getRoot().getPath().getPathString(); + if (!path.getPathString().startsWith(outputRootDir)) { + throw e; + } + + Path parentDir = path.getParentDirectory(); + if (!parentDir.isWritable() && parentDir.getPathString().startsWith(outputRootDir)) { + // Retry deleting after making the parent writable. + parentDir.setWritable(true); + deleteOutput(output); + } else if (path.isDirectory(Symlinks.NOFOLLOW)) { FileSystemUtils.deleteTree(path); } else { throw e; |