From a4a6b118726a73ebfd8577f003ff2d532b6c8d62 Mon Sep 17 00:00:00 2001 From: "fabio.sinibaldi" Date: Mon, 13 Nov 2017 13:38:38 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-transfer/data-transfer-service/2.0@158413 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../engine/impl/PersistenceProviderImpl.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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()); + } }