From 6ee8e6567d1ecee705cf4fbc9e8d0e56f4a87892 Mon Sep 17 00:00:00 2001 From: Sonia Zorba Date: Thu, 21 Jan 2021 16:02:38 +0100 Subject: [PATCH] Fixed concurrency issue on multiple files upload --- .../ia2/transfer/controller/PutFileController.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/inaf/ia2/transfer/controller/PutFileController.java b/src/main/java/it/inaf/ia2/transfer/controller/PutFileController.java index 440f8a3..0314f7b 100644 --- a/src/main/java/it/inaf/ia2/transfer/controller/PutFileController.java +++ b/src/main/java/it/inaf/ia2/transfer/controller/PutFileController.java @@ -83,9 +83,15 @@ public class PutFileController { File file = path.toFile(); - if (!file.getParentFile().exists()) { - if (!file.getParentFile().mkdirs()) { - throw new IllegalStateException("Unable to create parent folder: " + file.getParentFile().getAbsolutePath()); + /** + * This block must be synchronized, to avoid concurrency issues when + * multiple files are uploaded to a new folder in parallel. + */ + synchronized (this) { + if (!file.getParentFile().exists()) { + if (!file.getParentFile().mkdirs()) { + throw new IllegalStateException("Unable to create parent folder: " + file.getParentFile().getAbsolutePath()); + } } } -- GitLab