Re: (tomcat) branch main updated: Add support for shallow copies when using WebDAV
On 23/05/2024 12:53, Konstantin Kolinko wrote: вт, 21 мая 2024 г. в 14:55, : The following commit(s) were added to refs/heads/main by this push: new 4176706761 Add support for shallow copies when using WebDAV 4176706761 is described below commit 4176706761242851b14be303daf2a00ef385ee49 Author: Mark Thomas AuthorDate: Tue May 21 12:54:40 2024 +0100 Add support for shallow copies when using WebDAV @@ -1583,7 +1598,9 @@ public class WebdavServlet extends DefaultServlet implements PeriodicEventListen childSrc += "/"; } childSrc += entry; -copyResource(errorList, childSrc, childDest); +if (infiniteCopy) { +copyResource(errorList, childSrc, childDest, true); +} } I think that the "if (infiniteCopy)" block here is too narrow. The whole loop over children (starting with "String[] entries = resources.list(source)") here is useless when the infiniteCopy option is false. Thanks for the review. I've widened the block. Thinking about it the infinite/not infinite copy option is fairly pointless. For a file it has no impact. For a directory you either copy the whole tree or just create a new directory - and MKCOL can be used for that. Oh well. Mark - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org
Re: (tomcat) branch main updated: Add support for shallow copies when using WebDAV
вт, 21 мая 2024 г. в 14:55, : > > The following commit(s) were added to refs/heads/main by this push: > new 4176706761 Add support for shallow copies when using WebDAV > 4176706761 is described below > > commit 4176706761242851b14be303daf2a00ef385ee49 > Author: Mark Thomas > AuthorDate: Tue May 21 12:54:40 2024 +0100 > > Add support for shallow copies when using WebDAV > --- > .../apache/catalina/servlets/WebdavServlet.java| 31 > +- > webapps/docs/changelog.xml | 7 + > 2 files changed, 31 insertions(+), 7 deletions(-) > > diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java > b/java/org/apache/catalina/servlets/WebdavServlet.java > index a489eb0e51..b1b67030af 100644 > --- a/java/org/apache/catalina/servlets/WebdavServlet.java > +++ b/java/org/apache/catalina/servlets/WebdavServlet.java > @@ -1519,7 +1519,20 @@ public class WebdavServlet extends DefaultServlet > implements PeriodicEventListen > > Map 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) { > @@ -1548,16 +1561,18 @@ public class WebdavServlet extends DefaultServlet > implements PeriodicEventListen > /** > * Copy a collection. > * > - * @param errorList Map containing the list of errors which occurred > during the copy operation > - * @param sourcePath of the resource to be copied > - * @param dest Destination path > + * @param errorListMap 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 true if the copy was successful > */ > -private boolean copyResource(Map errorList, String > source, String dest) { > +private boolean copyResource(Map 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); > @@ -1583,7 +1598,9 @@ public class WebdavServlet extends DefaultServlet > implements PeriodicEventListen > childSrc += "/"; > } > childSrc += entry; > -copyResource(errorList, childSrc, childDest); > +if (infiniteCopy) { > +copyResource(errorList, childSrc, childDest, true); > +} > } I think that the "if (infiniteCopy)" block here is too narrow. The whole loop over children (starting with "String[] entries = resources.list(source)") here is useless when the infiniteCopy option is false. > } else if (sourceResource.isFile()) { > WebResource destResource = resources.getResource(dest); > diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org
(tomcat) branch main updated: Add support for shallow copies when using WebDAV
This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git The following commit(s) were added to refs/heads/main by this push: new 4176706761 Add support for shallow copies when using WebDAV 4176706761 is described below commit 4176706761242851b14be303daf2a00ef385ee49 Author: Mark Thomas AuthorDate: Tue May 21 12:54:40 2024 +0100 Add support for shallow copies when using WebDAV --- .../apache/catalina/servlets/WebdavServlet.java| 31 +- webapps/docs/changelog.xml | 7 + 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java b/java/org/apache/catalina/servlets/WebdavServlet.java index a489eb0e51..b1b67030af 100644 --- a/java/org/apache/catalina/servlets/WebdavServlet.java +++ b/java/org/apache/catalina/servlets/WebdavServlet.java @@ -1519,7 +1519,20 @@ public class WebdavServlet extends DefaultServlet implements PeriodicEventListen Map 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) { @@ -1548,16 +1561,18 @@ public class WebdavServlet extends DefaultServlet implements PeriodicEventListen /** * Copy a collection. * - * @param errorList Map containing the list of errors which occurred during the copy operation - * @param sourcePath of the resource to be copied - * @param dest Destination path + * @param errorListMap 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 true if the copy was successful */ -private boolean copyResource(Map errorList, String source, String dest) { +private boolean copyResource(Map 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); @@ -1583,7 +1598,9 @@ public class WebdavServlet extends DefaultServlet implements PeriodicEventListen childSrc += "/"; } childSrc += entry; -copyResource(errorList, childSrc, childDest); +if (infiniteCopy) { +copyResource(errorList, childSrc, childDest, true); +} } } else if (sourceResource.isFile()) { WebResource destResource = resources.getResource(dest); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 777667c181..aa3966382c 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -105,6 +105,13 @@ issues do not "pop up" wrt. others). --> + + + +Add support for shallow copies when using WebDAV. (markt) + + + - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org