This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new 462d8b0ffa Delete should remove any existing locks 462d8b0ffa is described below commit 462d8b0ffa7a3a5d1341c49d35187e6508c7593b Author: remm <r...@apache.org> AuthorDate: Wed Oct 16 11:54:48 2024 +0200 Delete should remove any existing locks --- .../apache/catalina/servlets/WebdavServlet.java | 29 +++++++++++++++++++--- .../catalina/servlets/TestWebdavServlet.java | 24 +++++++++++++++--- webapps/docs/changelog.xml | 4 +++ 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java b/java/org/apache/catalina/servlets/WebdavServlet.java index ef399b27f6..43c84f6770 100644 --- a/java/org/apache/catalina/servlets/WebdavServlet.java +++ b/java/org/apache/catalina/servlets/WebdavServlet.java @@ -1180,9 +1180,6 @@ public class WebdavServlet extends DefaultServlet implements PeriodicEventListen } else { - lock.tokens.add(lockToken); - resourceLocks.put(lock.path, lock); - // Checking if a resource exists at this path if (!resource.exists()) { @@ -1193,6 +1190,9 @@ public class WebdavServlet extends DefaultServlet implements PeriodicEventListen lockNullResources.computeIfAbsent(parentPath, k -> new CopyOnWriteArrayList<>()).add(lock.path); } + lock.tokens.add(lockToken); + resourceLocks.put(lock.path, lock); + // Add the Lock-Token header as by RFC 2518 8.10.1 // - only do this for newly created locks resp.addHeader("Lock-Token", "<opaquelocktoken:" + lockToken + ">"); @@ -1729,6 +1729,7 @@ public class WebdavServlet extends DefaultServlet implements PeriodicEventListen sendNotAllowed(req, resp); return false; } + resourceLocks.remove(path); } else { Map<String,Integer> errorList = new LinkedHashMap<>(); @@ -1750,6 +1751,16 @@ public class WebdavServlet extends DefaultServlet implements PeriodicEventListen */ errorList.put(path, Integer.valueOf(WebdavStatus.SC_METHOD_NOT_ALLOWED)); } + } else { + Iterator<LockInfo> collectionLocksList = collectionLocks.iterator(); + while (collectionLocksList.hasNext()) { + LockInfo lock = collectionLocksList.next(); + if (path.equals(lock.path)) { + collectionLocks.remove(lock); + break; + } + } + resourceLocks.remove(path); } if (!errorList.isEmpty()) { @@ -1828,6 +1839,18 @@ public class WebdavServlet extends DefaultServlet implements PeriodicEventListen */ errorList.put(childName, Integer.valueOf(WebdavStatus.SC_METHOD_NOT_ALLOWED)); } + } else { + if (childResource.isDirectory()) { + Iterator<LockInfo> collectionLocksList = collectionLocks.iterator(); + while (collectionLocksList.hasNext()) { + LockInfo lock = collectionLocksList.next(); + if (childName.equals(lock.path)) { + collectionLocks.remove(lock); + break; + } + } + } + resourceLocks.remove(childName); } } } diff --git a/test/org/apache/catalina/servlets/TestWebdavServlet.java b/test/org/apache/catalina/servlets/TestWebdavServlet.java index a3d3056a84..22688b6ddd 100644 --- a/test/org/apache/catalina/servlets/TestWebdavServlet.java +++ b/test/org/apache/catalina/servlets/TestWebdavServlet.java @@ -424,6 +424,15 @@ public class TestWebdavServlet extends TomcatBaseTest { } Assert.assertNotNull(lockTokenFile); + client.setRequest(new String[] { "PUT /myfolder/file5.txt HTTP/1.1" + SimpleHttpClient.CRLF + + "Host: localhost:" + getPort() + SimpleHttpClient.CRLF + + "Content-Length: 6" + SimpleHttpClient.CRLF + + "Connection: Close" + SimpleHttpClient.CRLF + + SimpleHttpClient.CRLF + CONTENT }); + client.connect(); + client.processRequest(true); + Assert.assertEquals(WebdavStatus.SC_LOCKED, client.getStatusCode()); + // Same but with lock token and lock null client.setRequest(new String[] { "PUT /myfolder/file5.txt HTTP/1.1" + SimpleHttpClient.CRLF + "Host: localhost:" + getPort() + SimpleHttpClient.CRLF + @@ -435,16 +444,25 @@ public class TestWebdavServlet extends TomcatBaseTest { client.processRequest(true); Assert.assertEquals(HttpServletResponse.SC_CREATED, client.getStatusCode()); - // Unlock for /myfolder/file5.txt - client.setRequest(new String[] { "UNLOCK /myfolder/file5.txt HTTP/1.1" + SimpleHttpClient.CRLF + + // Verify that this also removes the lock by doing another PUT without the token + client.setRequest(new String[] { "DELETE /myfolder/file5.txt HTTP/1.1" + SimpleHttpClient.CRLF + "Host: localhost:" + getPort() + SimpleHttpClient.CRLF + - "Lock-Token: " + lockTokenFile + SimpleHttpClient.CRLF + + "If: " + lockTokenFile + SimpleHttpClient.CRLF + "Connection: Close" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF }); client.connect(); client.processRequest(true); Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, client.getStatusCode()); + client.setRequest(new String[] { "PUT /myfolder/file5.txt HTTP/1.1" + SimpleHttpClient.CRLF + + "Host: localhost:" + getPort() + SimpleHttpClient.CRLF + + "Content-Length: 6" + SimpleHttpClient.CRLF + + "Connection: Close" + SimpleHttpClient.CRLF + + SimpleHttpClient.CRLF + CONTENT }); + client.connect(); + client.processRequest(true); + Assert.assertEquals(HttpServletResponse.SC_CREATED, client.getStatusCode()); + // Lock /myfolder again client.setRequest(new String[] { "LOCK /myfolder HTTP/1.1" + SimpleHttpClient.CRLF + "Host: localhost:" + getPort() + SimpleHttpClient.CRLF + diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 3ff2449385..ac3a13e769 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -156,6 +156,10 @@ Do not allow a new WebDAV lock on a child resource if a parent collection is locked (RFC 4918 section 6.1). (remm) </fix> + <fix> + WebDAV Delete should remove any existing lock on successfully deleted + resources. (remm) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org