From 28fb55406043c3385f96462f57a377e3339eb411 Mon Sep 17 00:00:00 2001 From: FY2QEQ Date: Thu, 18 Jul 2024 19:03:40 +0200 Subject: [PATCH] feat: better loggers for directory management --- .../fr/insee/arc/utils/files/FileUtilsArc.java | 17 ++++++++++++++++- .../fr/insee/arc/utils/minio/S3Template.java | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/files/FileUtilsArc.java b/arc-utils/src/main/java/fr/insee/arc/utils/files/FileUtilsArc.java index 6c8c1f5e2..e72181dff 100644 --- a/arc-utils/src/main/java/fr/insee/arc/utils/files/FileUtilsArc.java +++ b/arc-utils/src/main/java/fr/insee/arc/utils/files/FileUtilsArc.java @@ -37,7 +37,10 @@ public static boolean isCompletelyWritten(File file) { */ public static void createDirIfNotexist(File directoryToCreate) { if (!directoryToCreate.exists()) { - directoryToCreate.mkdirs(); + if (!directoryToCreate.mkdirs()) + { + LoggerHelper.error(LOGGER, "Le répertoire ", directoryToCreate.getAbsolutePath(), " n'a pas pu être créé"); + } } } @@ -46,6 +49,18 @@ public static void createDirIfNotexist(File directoryToCreate) { * @param f */ public static void createDirIfNotexist(String fPath) { + + File fileToProceed = new File(fPath); + + if (fileToProceed.exists() && !fileToProceed.isDirectory()) + { + try { + delete(fileToProceed); + } catch (ArcException e) { + LoggerHelper.error(LOGGER, "Le fichier ", fileToProceed.getAbsolutePath(), " n'a pas pu être effacé"); + } + } + createDirIfNotexist(new File(fPath)); } diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java b/arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java index b4aaf70c4..e11806ce7 100644 --- a/arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java +++ b/arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java @@ -202,7 +202,7 @@ public void download(String sourceS3Path, String targetFilePath) throws ArcExcep | InvalidResponseException | NoSuchAlgorithmException | ServerException | XmlParserException | IllegalArgumentException | IOException e) { - throw new ArcException(ArcExceptionMessage.FILE_COPY_FAILED, sourceS3Path, targetFile.getName()); + throw new ArcException(ArcExceptionMessage.FILE_COPY_FAILED, sourceS3Path, targetFile.getAbsolutePath()); } } @@ -234,7 +234,7 @@ public void upload(File fileFrom, String pathTo) throws ArcException { | InvalidResponseException | NoSuchAlgorithmException | ServerException | XmlParserException | IllegalArgumentException | IOException e) { - throw new ArcException(ArcExceptionMessage.FILE_COPY_FAILED, fileFrom.getName(), pathTo); + throw new ArcException(ArcExceptionMessage.FILE_COPY_FAILED, fileFrom.getAbsolutePath(), pathTo); } }