Skip to content

Commit

Permalink
Add support for shallow copies when using WebDAV
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed May 21, 2024
1 parent 9512145 commit 4176706
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
31 changes: 24 additions & 7 deletions java/org/apache/catalina/servlets/WebdavServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,20 @@ private boolean copyResource(HttpServletRequest req, HttpServletResponse resp) t

Map<String,Integer> errorList = new HashMap<>();

boolean result = copyResource(errorList, path, destinationPath);
boolean infiniteCopy = true;
String depthHeader = req.getHeader("Depth");
if (depthHeader != null) {
if (depthHeader.equals("infinity")) {
// NO-OP - this is the default
} else if (depthHeader.equals("0")) {
infiniteCopy = false;
} else {
resp.sendError(WebdavStatus.SC_BAD_REQUEST);
return false;
}
}

boolean result = copyResource(errorList, path, destinationPath, infiniteCopy);

if ((!result) || (!errorList.isEmpty())) {
if (errorList.size() == 1) {
Expand Down Expand Up @@ -1548,16 +1561,18 @@ private boolean copyResource(HttpServletRequest req, HttpServletResponse resp) t
/**
* Copy a collection.
*
* @param errorList Map containing the list of errors which occurred during the copy operation
* @param source Path of the resource to be copied
* @param dest Destination path
* @param errorList Map containing the list of errors which occurred during the copy operation
* @param source Path of the resource to be copied
* @param dest Destination path
* @param infiniteCopy {@code true} if this copy is to be an infinite copy, otherwise {@code false} for a shallow
* copy
*
* @return <code>true</code> if the copy was successful
*/
private boolean copyResource(Map<String,Integer> errorList, String source, String dest) {
private boolean copyResource(Map<String,Integer> errorList, String source, String dest, boolean infiniteCopy) {

if (debug > 1) {
log("Copy: " + source + " To: " + dest);
log("Copy: " + source + " To: " + dest + " Infinite: " + infiniteCopy);
}

WebResource sourceResource = resources.getResource(source);
Expand All @@ -1583,7 +1598,9 @@ private boolean copyResource(Map<String,Integer> errorList, String source, Strin
childSrc += "/";
}
childSrc += entry;
copyResource(errorList, childSrc, childDest);
if (infiniteCopy) {
copyResource(errorList, childSrc, childDest, true);
}
}
} else if (sourceResource.isFile()) {
WebResource destResource = resources.getResource(dest);
Expand Down
7 changes: 7 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@
issues do not "pop up" wrt. others).
-->
<section name="Tomcat 11.0.0-M21 (markt)" rtext="in development">
<subsection name="Catalina">
<changelog>
<add>
Add support for shallow copies when using WebDAV. (markt)
</add>
</changelog>
</subsection>
<subsection name="Coyote">
<changelog>
<fix>
Expand Down

0 comments on commit 4176706

Please sign in to comment.