Fabio Sinibaldi 2017-11-13 13:38:38 +00:00
parent 8fccae4fe6
commit a4a6b11872
1 changed files with 11 additions and 3 deletions

View File

@ -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());
}
}