gianm commented on a change in pull request #6677: FileUtils: Sync directory
entry too on writeAtomically.
URL: https://github.com/apache/incubator-druid/pull/6677#discussion_r237290419
##########
File path: core/src/main/java/org/apache/druid/java/util/common/FileUtils.java
##########
@@ -182,22 +187,34 @@ public static MappedByteBufferHandler map(File file)
throws IOException
*
* This method is not just thread-safe, but is also safe to use from
multiple processes on the same machine.
*/
- public static void writeAtomically(final File file, OutputStreamConsumer f)
throws IOException
+ public static <T> T writeAtomically(final File file, OutputStreamConsumer<T>
f) throws IOException
{
- writeAtomically(file, file.getParentFile(), f);
+ return writeAtomically(file, file.getParentFile(), f);
}
- private static void writeAtomically(final File file, final File tmpDir,
OutputStreamConsumer f) throws IOException
+ private static <T> T writeAtomically(final File file, final File tmpDir,
OutputStreamConsumer<T> f) throws IOException
{
final File tmpFile = new File(tmpDir, StringUtils.format(".%s.%s",
file.getName(), UUID.randomUUID()));
- try {
- try (final FileOutputStream out = new FileOutputStream(tmpFile)) {
+ //noinspection unused
+ try (final Closeable deleter = () ->
java.nio.file.Files.deleteIfExists(tmpFile.toPath())) {
Review comment:
I think that's fine. It would be a shock to have it fail, and maybe it's
best to propagate in that case.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]