/** * Helper method to remove an Artifact. If the Artifact refers to a directory recursively removes * the contents of the directory. */ protected void deleteOutput(Artifact output) throws IOException { Path path = output.getPath(); try { // 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) { FileSystemUtils.deleteTree(path); } else { throw e; } } }
/** If the action might create directories as outputs this method must be called. */ protected void checkOutputsForDirectories(EventHandler eventHandler) { for (Artifact output : getOutputs()) { Path path = output.getPath(); String ownerString = Label.print(getOwner().getLabel()); if (path.isDirectory()) { eventHandler.handle( new Event( EventKind.WARNING, getOwner().getLocation(), "output '" + output.prettyPrint() + "' of " + ownerString + " is a directory; dependency checking of directories is unsound", ownerString)); } } }