This is an automated email from the ASF dual-hosted git repository.

remm 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 baa77ba7fa Delete should remove any existing locks
baa77ba7fa is described below

commit baa77ba7faa4eee524c7cc2eb7d15610dd9c335e
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 15843652bd..57c1b56021 100644
--- a/java/org/apache/catalina/servlets/WebdavServlet.java
+++ b/java/org/apache/catalina/servlets/WebdavServlet.java
@@ -1182,9 +1182,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()) {
 
@@ -1195,6 +1192,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 + ">");
@@ -1731,6 +1731,7 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
                 sendNotAllowed(req, resp);
                 return false;
             }
+            resourceLocks.remove(path);
         } else {
 
             Map<String,Integer> errorList = new LinkedHashMap<>();
@@ -1752,6 +1753,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()) {
@@ -1830,6 +1841,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 d94984606e..7b5a3cac1b 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -171,6 +171,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

Reply via email to