Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ant RecursiveGet: fixed exception, added skipExistingFiles option #323

Merged
merged 2 commits into from
Jul 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}