diff --git a/src/main/java/org/gcube/data/transfer/service/transfers/engine/impl/PersistenceProviderImpl.java b/src/main/java/org/gcube/data/transfer/service/transfers/engine/impl/PersistenceProviderImpl.java index 75ffc32..55988ce 100644 --- a/src/main/java/org/gcube/data/transfer/service/transfers/engine/impl/PersistenceProviderImpl.java +++ b/src/main/java/org/gcube/data/transfer/service/transfers/engine/impl/PersistenceProviderImpl.java @@ -3,7 +3,6 @@ package org.gcube.data.transfer.service.transfers.engine.impl; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.HashSet; import java.util.Set; @@ -126,8 +125,8 @@ public class PersistenceProviderImpl implements PersistenceProvider { break; } case FAIL: throw new DestinationAccessException("Found existing "+clashing.getAbsolutePath()+"policy is "+policy); - case REWRITE : { - Files.deleteIfExists(Paths.get(clashing.getAbsolutePath())); + case REWRITE : { + deleteRecursively(clashing); if(dir)clashing.mkdirs(); else clashing.createNewFile(); break; @@ -138,4 +137,13 @@ public class PersistenceProviderImpl implements PersistenceProvider { } return clashing; } + + + private static final void deleteRecursively(File toDelete) throws IOException { + log.warn("Recursively deleting {} ",toDelete.getAbsolutePath()); + if(toDelete.isDirectory()) { + for(File child:toDelete.listFiles()) + deleteRecursively(child); + }else Files.deleteIfExists(toDelete.toPath()); + } }