Skip to content

Commit

Permalink
FISH-6606 use temporary filename only while saving the uploaded file
Browse files Browse the repository at this point in the history
Upgrade of common-upload probably changed the behaviour of saving file,
now it fails if the target file already exists. Now, we use only the
filename.
The temp file is still created as Java always creates it, it is
deleted before the uploaded file is written.
  • Loading branch information
aubi committed Nov 2, 2022
1 parent d7cbb99 commit cb7ccdc
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2022] Payara Foundation and/or its affiliates

/*
* CommonHandlers.java
Expand Down Expand Up @@ -181,11 +182,12 @@ public static void uploadFileToTempDir(HandlerContext handlerCtx) {
prefix = prefix + new SecureRandom().nextInt(100000);
}
tmpFile = File.createTempFile(prefix, suffix);
FileUtils.deleteOnExit(tmpFile);
tmpFile.delete(); // remove the file as uploader fails, if it exists
if (logger.isLoggable(Level.FINE)) {
logger.fine(GuiUtil.getCommonMessage("log.writeToTmpFile"));
}
uploadedFile.write(tmpFile);
FileUtils.deleteOnExit(tmpFile);
if (logger.isLoggable(Level.FINE)) {
logger.fine(GuiUtil.getCommonMessage("log.afterWriteToTmpFile"));
}
Expand Down

0 comments on commit cb7ccdc

Please sign in to comment.