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 1e9cba6c73 Minor fixes
1e9cba6c73 is described below

commit 1e9cba6c7391689445ec7dce7b3894cad27be13e
Author: remm <r...@apache.org>
AuthorDate: Thu Oct 24 09:34:05 2024 +0200

    Minor fixes
    
    Stop using the Lock-Token header for isLocked (clearly not used for
    that).
    More accurate matching of the token (append : and >).
    Cleanup the unlock for shared locks, although no real change (unless
    there's a token with no shared lock anymore, which should not really
    happen).
    Drop old unlockResource method (the shared lock unlock probably had some
    issue since it seemed to only remove the first one), and replace it with
    a much simpler deletedResource.
---
 .../apache/catalina/servlets/WebdavServlet.java    | 83 +++++++++-------------
 1 file changed, 32 insertions(+), 51 deletions(-)

diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java 
b/java/org/apache/catalina/servlets/WebdavServlet.java
index ffa841824d..ce144c1ed4 100644
--- a/java/org/apache/catalina/servlets/WebdavServlet.java
+++ b/java/org/apache/catalina/servlets/WebdavServlet.java
@@ -1632,14 +1632,14 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
                     } else {
                         if ((parentPath != path && parentLock.depth > 0) || 
parentPath == path) {
                             if (parentLock.isExclusive()) {
-                                if (ifHeader.contains(parentLock.token) && 
(parentLock.principal == null ||
+                                if (ifHeader.contains(":" + parentLock.token + 
">") && (parentLock.principal == null ||
                                         
parentLock.principal.equals(req.getRemoteUser()))) {
                                     toRenew = parentLock;
                                     break;
                                 }
                             } else {
                                 for (String token : parentLock.sharedTokens) {
-                                    if (ifHeader.contains(token)) {
+                                    if (ifHeader.contains(":" + token + ">")) {
                                         LockInfo sharedLock = 
sharedLocks.get(token);
                                         if (sharedLock != null && 
(sharedLock.principal == null ||
                                                 
sharedLock.principal.equals(req.getRemoteUser()))) {
@@ -1732,7 +1732,7 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
                 } else {
                     if ((parentPath != path && parentLock.depth > 0) || 
parentPath == path) {
                         if (parentLock.isExclusive()) {
-                            if (lockTokenHeader.contains(parentLock.token) && 
(parentLock.principal == null ||
+                            if (lockTokenHeader.contains(":" + 
parentLock.token + ">") && (parentLock.principal == null ||
                                     
parentLock.principal.equals(req.getRemoteUser()))) {
                                 resourceLocks.remove(parentPath);
                                 unlocked = true;
@@ -1744,23 +1744,25 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
                             }
                         } else {
                             for (String token : parentLock.sharedTokens) {
-                                if (lockTokenHeader.contains(token)) {
+                                if (lockTokenHeader.contains(":" + token + 
">")) {
                                     LockInfo lock = sharedLocks.get(token);
-                                    if (lock == null || lock.principal == null 
||
-                                            
lock.principal.equals(req.getRemoteUser())) {
-                                        if ((parentPath != path && lock != 
null && lock.depth > 0) ||
-                                                parentPath == path) {
+                                    if (lock == null) {
+                                        parentLock.sharedTokens.remove(token);
+                                    } else if (lock.principal == null || 
lock.principal.equals(req.getRemoteUser())) {
+                                        // The shared lock might not have the 
same depth
+                                        if ((parentPath != path && lock.depth 
> 0) || parentPath == path) {
                                             
parentLock.sharedTokens.remove(token);
-                                            if 
(parentLock.sharedTokens.isEmpty()) {
-                                                
resourceLocks.remove(parentPath);
-                                            }
                                             sharedLocks.remove(token);
                                             unlocked = true;
-                                            break;
                                         }
                                     }
+                                    // Unlike the if header, this can only 
match one token
+                                    break;
                                 }
                             }
+                            if (parentLock.sharedTokens.isEmpty()) {
+                                resourceLocks.remove(parentPath);
+                            }
                         }
                     }
                 }
@@ -1889,13 +1891,7 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
             ifHeader = "";
         }
 
-        // Normally a lock token is not sent using this header
-        String lockTokenHeader = req.getHeader("Lock-Token");
-        if (lockTokenHeader == null) {
-            lockTokenHeader = "";
-        }
-
-        return isLocked(path, req.getRemoteUser(), ifHeader + lockTokenHeader);
+        return isLocked(path, req.getRemoteUser(), ifHeader);
     }
 
 
@@ -1931,11 +1927,13 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
                             for (String token : parentLock.sharedTokens) {
                                 LockInfo lock = sharedLocks.get(token);
                                 if (lock != null) {
+                                    // The shared lock might not have the same 
depth
                                     if ((parentPath != path && lock.depth > 0) 
|| parentPath == path) {
                                         if (ifHeader.contains(":" + token + 
">") &&
                                                 (lock.principal == null || 
lock.principal.equals(principal))) {
                                             return false;
                                         }
+                                        // Since it is a shared lock, continue 
to look up the tree but note that there was a lock
                                         unmatchedSharedLock = true;
                                     }
                                 }
@@ -2271,7 +2269,7 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
                 sendNotAllowed(req, resp);
                 return false;
             }
-            unlockResource(path, null);
+            deletedResource(path);
         } else {
 
             Map<String,Integer> errorList = new LinkedHashMap<>();
@@ -2294,7 +2292,7 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
                     errorList.put(path, 
Integer.valueOf(WebdavStatus.SC_METHOD_NOT_ALLOWED));
                 }
             } else {
-                unlockResource(path, null);
+                deletedResource(path);
             }
 
             if (!errorList.isEmpty()) {
@@ -2308,29 +2306,6 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
         return true;
     }
 
-    private void unlockResource(String path, String lockToken) {
-        LockInfo lock = resourceLocks.get(path);
-        if (lock != null) {
-            if (lock.isExclusive()) {
-                if (lockToken == null || lockToken.contains(lock.token)) {
-                    resourceLocks.remove(path);
-                }
-            } else {
-                for (String token : lock.sharedTokens) {
-                    if (lockToken == null || lockToken.contains(token)) {
-                        lock.sharedTokens.remove(token);
-                        if (lock.sharedTokens.isEmpty()) {
-                            resourceLocks.remove(lock.path);
-                        }
-                        sharedLocks.remove(token);
-                        break;
-                    }
-                }
-            }
-        }
-        store.delete(path);
-    }
-
 
     /**
      * Deletes a collection.
@@ -2355,11 +2330,6 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
         if (ifHeader == null) {
             ifHeader = "";
         }
-        String lockTokenHeader = req.getHeader("Lock-Token");
-        if (lockTokenHeader == null) {
-            lockTokenHeader = "";
-        }
-        String lockHeader = ifHeader + lockTokenHeader;
 
         String[] entries = resources.list(path);
 
@@ -2370,7 +2340,7 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
             }
             childName += entry;
 
-            if (isLocked(childName, req.getRemoteUser(), lockHeader)) {
+            if (isLocked(childName, req.getRemoteUser(), ifHeader)) {
 
                 errorList.put(childName, 
Integer.valueOf(WebdavStatus.SC_LOCKED));
 
@@ -2397,13 +2367,24 @@ public class WebdavServlet extends DefaultServlet 
implements PeriodicEventListen
                         errorList.put(childName, 
Integer.valueOf(WebdavStatus.SC_METHOD_NOT_ALLOWED));
                     }
                 } else {
-                    unlockResource(childName, null);
+                    deletedResource(childName);
                 }
             }
         }
     }
 
 
+    private void deletedResource(String path) {
+        LockInfo lock = resourceLocks.remove(path);
+        if (lock != null && !lock.isExclusive()) {
+            for (String token : lock.sharedTokens) {
+                sharedLocks.remove(token);
+            }
+        }
+        store.delete(path);
+    }
+
+
     /**
      * Send a multistatus element containing a complete error report to the 
client.
      *


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to