In Guava 10+, Google deprecated Files.deleteDirectoryContents(). JavaDoc says
Deprecated. This method suffers from poor symlink detection and race conditions. This functionality can be supported suitably only by shelling out to an operating system command such as rm -rf or del /s. This method is scheduled to be removed from Guava in Guava release 11.0
I am confused on why there is a race condition. I think having this method is actually useful and find shelling out to operating system a poor solution. Can the authors share why the made this decision?
I am confused on why there is a race condition.
For example, suppose that one thread calls Files.deleteDirectoryContents()
and a second thread (or an external process) simultaneously creates a new file in the directory.
When you return from the call, can you rely on the directory being empty? Nope!
Anyway, if you find the functionality of this method to be useful ... despite its flaws ... you are free to take a copy of the code, tweak it, and embed it in your application. (Just check the Guava source code license and make sure that you conform to it.)
Can the authors share why the made this decision?
I think that they already have; see the deprecation notice. If you want more, try searching the issue tracker and the Guava discussion group. You could even try asking politely on the discussion group, though if your agenda is to change their minds, I doubt that you will succeed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With