diff --git a/src/main/java/com/github/sardine/ant/command/RecursiveGet.java b/src/main/java/com/github/sardine/ant/command/RecursiveGet.java index 43a346ba..172277bd 100644 --- a/src/main/java/com/github/sardine/ant/command/RecursiveGet.java +++ b/src/main/java/com/github/sardine/ant/command/RecursiveGet.java @@ -13,7 +13,7 @@ /** * A nice ant wrapper around sardine.list() and sardine.get(). - * + * * @author andreafonti */ public class RecursiveGet extends Command { @@ -36,6 +36,11 @@ public class RecursiveGet extends Command { */ boolean overwriteFiles = false; + /** + * true if existent local files will be skipped; otherwise, false. + */ + boolean skipExistingFiles = false; + /** * {@inheritDoc} */ @@ -78,12 +83,16 @@ protected void execute() throws Exception { String filePathRelativeToRemoteDirectory = davResource.getPath().replace(remoteDirectoryPath, ""); Path localFilePath = Paths.get(localDirectory, filePathRelativeToRemoteDirectory); + if (skipExistingFiles && Files.exists(localFilePath)) { + log("skipping download of already existing file " + localFilePath); + continue; + } + Files.createDirectories(localFilePath.getParent()); log("downloading " + filePathRelativeToRemoteDirectory + " to " + localFilePath); - String remoteFileUrl = new URI(serverUrl + '/').resolve(davResource.getPath()).toString(); - InputStream ioStream = getSardine().get(remoteFileUrl); + InputStream ioStream = getSardine().get(serverUrl + davResource.getHref().toString()); try { if (overwriteFiles) { Files.copy(ioStream, localFilePath, StandardCopyOption.REPLACE_EXISTING); @@ -115,4 +124,7 @@ public void setOverwriteFiles(boolean overwriteFiles) { this.overwriteFiles = overwriteFiles; } + public void setSkipExistingFiles(boolean skipExistingFiles) { + this.skipExistingFiles = skipExistingFiles; + } }