From 0d23a6e16a874ee398d9d2821dfbecf47cb5d38d Mon Sep 17 00:00:00 2001 From: Luke Sikina Date: Thu, 21 Dec 2023 16:13:57 -0500 Subject: [PATCH] race condition --- .../hpds/service/filesharing/FileSystemService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/filesharing/FileSystemService.java b/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/filesharing/FileSystemService.java index 73ab08ee..2ba0a585 100644 --- a/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/filesharing/FileSystemService.java +++ b/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/filesharing/FileSystemService.java @@ -45,8 +45,10 @@ private boolean writeStreamToFile(String fileName, InputStream content, String q try { LOG.info("Writing query {} to file: {}", queryId, filePath); - if (!Files.exists(dirPath)) { - Files.createDirectory(dirPath); + synchronized (dirPath) { + if (!Files.exists(dirPath)) { + Files.createDirectory(dirPath); + } } return Files.copy(content, filePath) > 0; } catch (IOException e) {