Skip to content

Commit

Permalink
Sardine: Add additional "move" method (with lock token)
Browse files Browse the repository at this point in the history
  • Loading branch information
rt1shnik committed Feb 5, 2020
1 parent 9c38596 commit 8ad210b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/thegrizzlylabs/sardineandroid/Sardine.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ public interface Sardine
*/
void move(String sourceUrl, String destinationUrl, boolean overwrite) throws IOException;

/**
* Move a url to from source to destination using WebDAV <code>MOVE</code>.
*
* @param sourceUrl Path to the resource including protocol and hostname
* @param destinationUrl Path to the resource including protocol and hostname
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
* @throws IOException I/O error or HTTP response validation failure
*/
void move(String sourceUrl, String destinationUrl, boolean overwrite, String lockTocken) throws IOException;

/**
* Copy a url from source to destination using WebDAV <code>COPY</code>. Assumes overwrite.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,20 @@ public void move(String sourceUrl, String destinationUrl) throws IOException {

@Override
public void move(String sourceUrl, String destinationUrl, boolean overwrite) throws IOException {
Request request = new Request.Builder()
move(sourceUrl, destinationUrl, overwrite, null);
}

@Override
public void move(String sourceUrl, String destinationUrl, boolean overwrite, String lockToken) throws IOException {
Request.Builder buildsr = new Request.Builder()
.url(sourceUrl)
.method("MOVE", null)
.header("DESTINATION", URI.create(destinationUrl).toASCIIString())
.header("OVERWRITE", overwrite ? "T" : "F")
.build();
.header("OVERWRITE", overwrite ? "T" : "F");
if (lockToken != null) {
buildsr.header("If", "<" + destinationUrl + "> (<" + lockToken + ">)");
}
Request request = buildsr.build();
execute(request);
}

Expand Down

0 comments on commit 8ad210b

Please sign in to comment.