Skip to content

Commit

Permalink
More carefully check file creation status (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 authored Oct 17, 2023
1 parent 47bd077 commit 441caf0
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -537,17 +537,23 @@ private static Optional<File> handleTempFileCreation(UploadedFile file) {
new File(Path.of(System.getProperty("java.io.tmpdir"), file.filename()).toString());
boolean makeDirsRes = tempFilePath.getParentFile().mkdirs();

if (!makeDirsRes) {
if (!makeDirsRes && !(tempFilePath.getParentFile().exists())) {
logger.error(
"There was an error while uploading " + file.filename() + " to the temp folder!");
"There was an error while creating "
+ tempFilePath.getAbsolutePath()
+ "! Exists: "
+ tempFilePath.getParentFile().exists());
return Optional.empty();
}

try {
FileUtils.copyInputStreamToFile(file.content(), tempFilePath);
} catch (IOException e) {
logger.error(
"There was an error while uploading " + file.filename() + " to the temp folder!");
"There was an error while copying "
+ file.filename()
+ " to the temp file "
+ tempFilePath.getAbsolutePath());
return Optional.empty();
}

Expand Down

0 comments on commit 441caf0

Please sign in to comment.