gianm opened a new pull request #11879:
URL: https://github.com/apache/druid/pull/11879
The changes:
- Add `void mkdirp(File directory) throws IOException` to FileUtils, which
has semantics like Unix `mkdir -p`. It creates a directory if it does not
exist, returns quietly if it already exists, and generates an error if it could
not be created.
- Migrate usages of File.mkdirs to the new function and add File.mkdirs to
the forbidden functions list.
The new method is better for two reasons:
First, File.mkdirs makes it easy to ignore errors, since it returns a
boolean. Unchecked usage is common and leads to confusing errors later, like
"Cannot create file [dir/file]", instead of more-specific errors upfront like
"Cannot create directory [dir]".
Second, File.mkdirs is not concurrency safe. "Natural" patterns like this
with File.mkdirs are prone to race conditions, because two `dir.mkdirs()` that
run concurrently cannot both succeed:
```
if (!dir.exists() && !dir.mkdirs()) {
throw new IOException();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]