diff --git a/src/main/java/org/gcube/dataanalysis/executor/rscripts/generic/FileUtils.java b/src/main/java/org/gcube/dataanalysis/executor/rscripts/generic/FileUtils.java index 16cb809..04b0ee3 100644 --- a/src/main/java/org/gcube/dataanalysis/executor/rscripts/generic/FileUtils.java +++ b/src/main/java/org/gcube/dataanalysis/executor/rscripts/generic/FileUtils.java @@ -2841,6 +2841,26 @@ public class FileUtils { } } + public static void moveFileToDirectory(File srcFile, File destDir, File dstFile, boolean createDestDir) throws IOException { + if (srcFile == null) { + throw new NullPointerException("Source must not be null"); + } + if (destDir == null) { + throw new NullPointerException("Destination directory must not be null"); + } + if (!destDir.exists() && createDestDir) { + destDir.mkdirs(); + } + if (!destDir.exists()) { + throw new FileNotFoundException("Destination directory '" + destDir + + "' does not exist [createDestDir=" + createDestDir +"]"); + } + if (!destDir.isDirectory()) { + throw new IOException("Destination '" + destDir + "' is not a directory"); + } + moveFile(srcFile, new File(destDir, dstFile.getName())); + } + /** * Moves a file to a directory. * diff --git a/src/main/java/org/gcube/dataanalysis/executor/rscripts/generic/GenericRScript.java b/src/main/java/org/gcube/dataanalysis/executor/rscripts/generic/GenericRScript.java index ad843f4..fa958e7 100644 --- a/src/main/java/org/gcube/dataanalysis/executor/rscripts/generic/GenericRScript.java +++ b/src/main/java/org/gcube/dataanalysis/executor/rscripts/generic/GenericRScript.java @@ -236,10 +236,10 @@ public abstract class GenericRScript extends StandardLocalInfraAlgorithm { } if (rowFile.exists()) { - String preparedFile = new File(config.getConfigPath(), rowFile.getName()).getAbsolutePath(); + String preparedFile = new File(config.getConfigPath(), UUID.randomUUID()+rowFile.getName()).getAbsolutePath(); LOGGER.debug("Copying " + rowFile.getAbsolutePath() + " to " + preparedFile); try{ - org.gcube.dataanalysis.executor.rscripts.generic.FileUtils.moveFileToDirectory(rowFile, new File(config.getConfigPath()), false); + org.gcube.dataanalysis.executor.rscripts.generic.FileUtils.moveFileToDirectory(rowFile, new File(config.getConfigPath()),new File(preparedFile), false); files.add(preparedFile); }catch(Exception e){ LOGGER.error("error in moving file "+rowFile.getAbsolutePath()+" to "+preparedFile,e);