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

remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 831d17afe7 Delete should remove any existing locks
831d17afe7 is described below

commit 831d17afe719c95c3d6b4771ca803992d94deb95
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 e445013203..5afac2ac61 100644
--- a/java/org/apache/catalina/servlets/WebdavServlet.java
+++ b/java/org/apache/catalina/servlets/WebdavServlet.java
@@ -1179,9 +1179,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()) {
 
@@ -1192,6 +1189,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 + ">");
@@ -1728,6 +1728,7 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
                 sendNotAllowed(req, resp);
                 return false;
             }
+            resourceLocks.remove(path);
         } else {
 
             Map<String,Integer> errorList = new LinkedHashMap<>();
@@ -1749,6 +1750,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()) {
@@ -1827,6 +1838,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 70fc7efefc..8fe84abb85 100644
--- a/test/org/apache/catalina/servlets/TestWebdavServlet.java
+++ b/test/org/apache/catalina/servlets/TestWebdavServlet.java
@@ -423,6 +423,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 +
@@ -434,16 +443,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 8712aad36d..67ffcee4ed 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

Reply via email to