JDK-7148952 : (fs) Add Files.deleteFileTree to delete a file tree
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux_ubuntu
  • CPU: x86
  • Submitted: 2012-02-26
  • Updated: 2012-03-20
Description
A DESCRIPTION OF THE REQUEST :
According to http://code.google.com/p/guava-libraries/issues/detail?id=365 it is impossible to safely delete a path recursively using Java due to race conditions.

As such, I am proposing the following API be added:

Files.delete(Path, DeleteOption...) where StandardDeleteOption.RECURSIVELY specifies that children paths should be deleted as well.

JUSTIFICATION :
This is a commonly-requested feature that is difficult to implement in a cross-platform and secure manner. As such, it should be provided by the core API.

Comments
EVALUATION JSR-203/JDK7 focused on primitives and so did not add recursive operations java.nio.file.Files. Clearly therse are desirable and Files should at least define methods for the most common operations such as deleteFileTree and copyFileTree. The main issue is dealing with I/O errors as there are many approaches. As regards doing rm -r in a secure manner then the primitives required are defined by java.nio.file.SecureDirectoryStream. SecureDirectoryStream requires support from the underlying operating system and so it not implemented by all providers. It is implemented by Oracle's providers on Linux and Solaris.
26-02-2012