Skip to content

Commit

Permalink
Merge pull request #323 from Jonomir/master
Browse files Browse the repository at this point in the history
Ant RecursiveGet: fixed exception, added skipExistingFiles option
  • Loading branch information
lookfirst authored Jul 10, 2020
2 parents 74cccd9 + 1beaab1 commit f97cc9e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/com/github/sardine/ant/command/RecursiveGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* A nice ant wrapper around sardine.list() and sardine.get().
*
*
* @author andreafonti
*/
public class RecursiveGet extends Command {
Expand All @@ -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}
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -115,4 +124,7 @@ public void setOverwriteFiles(boolean overwriteFiles) {
this.overwriteFiles = overwriteFiles;
}

public void setSkipExistingFiles(boolean skipExistingFiles) {
this.skipExistingFiles = skipExistingFiles;
}
}

0 comments on commit f97cc9e

Please sign in to comment.