]> source.dussan.org Git - nextcloud-server.git/commitdiff
mayor improvements in the handling of locks in webdav
authorRobin Appelman <icewind1991@gmail.com>
Sun, 4 Jul 2010 22:39:38 +0000 (00:39 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Sun, 4 Jul 2010 22:39:38 +0000 (00:39 +0200)
inc/HTTP/WebDAV/Server/Filesystem.php

index 72e747439d53aca037672b966aa389d6c90da782..b96fb414c27fbfe8376ec0b343b2ce00cba506c0 100755 (executable)
     function PUT(&$options) 
     {
         $fspath = $options["path"];
-
         $dir = dirname($fspath);
         if (!OC_FILESYSTEM::file_exists($dir) || !OC_FILESYSTEM::is_dir($dir)) {
             return "409 Conflict"; // TODO right status code for both?
         if (!OC_FILESYSTEM::file_exists($path)) {
             return "404 Not found";
         }
-
+               $lock=self::checkLock($path);
+               if(is_array($lock)){
+                       $owner=$options['owner'];
+                       $lockOwner=$lock['owner'];
+                       if($owner==$lockOwner){
+                               return "423 Locked";
+                       }
+               }
         if (OC_FILESYSTEM::is_dir($path)) {
                 $query = "DELETE FROM properties WHERE path LIKE '".$this->_slashify($options["path"])."%'";
                 OC_DB::query($query);
     {
         // get absolute fs path to requested resource
         $fspath = $options["path"];
-
         // TODO recursive locks on directories not supported yet
         // makes litmus test "32. lock_collection" fail
-        if (is_dir($fspath) && !empty($options["depth"])) {
-            return "409 Conflict";
+        if (OC_FILESYSTEM::is_dir($fspath) && !empty($options["depth"])) {
+            switch($options["depth"]){
+                               case 'infinity':
+                                       $recursion=1;
+                                       break;
+                               case '0':
+                                       $recursion=0;
+                                       break;
+            }
+        }else{
+                       $recursion=0;
         }
 
         $options["timeout"] = time()+300; // 5min. hardcoded
             $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
 
             $query = "SELECT owner, exclusivelock FROM locks $where";
-            $res   = OC_DB::query($query);
-            $row   = OC_DB::fetch_assoc($res);
-            OC_DB::free_result($res);
+            $res   = OC_DB::select($query);
 
-            if (is_array($row)) {
+            if (is_array($res) and isset($res[0])) {
+                               $row=$res[0];
                 $query = "UPDATE `locks` SET `expires` = '$options[timeout]', `modified` = ".time()." $where";
                 OC_DB::query($query);
                 
                 $options['type']  = $row["exclusivelock"] ? "write"     : "read";
 
                 return true;
-            } else {
-                return false;
+            } else {//check for indirect refresh
+               $query = "SELECT *
+                  FROM locks
+                 WHERE recursive = 1
+               ";
+            $res = OC_DB::select($query);
+            foreach($res as $row){
+                               if(strpos($options['path'],$row['path'])==0){//are we a child of a folder with an recursive lock
+                                       $where = "WHERE path = '$row[path]' AND token = '$options[update]'";
+                                        $query = "UPDATE `locks` SET `expires` = '$options[timeout]', `modified` = ".time()." $where";
+                OC_DB::query($query);
+                $options['owner'] = $row['owner'];
+                $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
+                $options['type']  = $row["exclusivelock"] ? "write"     : "read";
+                return true;
+                               }
+            }
             }
         }
             
                           , `modified` = ".time()."
                           , `owner`   = '$options[owner]'
                           , `expires` = '$options[timeout]'
-                          , `exclusivelock`  = " .($options['scope'] === "exclusive" ? "1" : "0")
-            ;
+                          , `exclusivelock`  = " .($options['scope'] === "exclusive" ? "1" : "0")."
+                          , `recursive` = $recursion";
             OC_DB::query($query);
-
-            return OC_DB::affected_rows() ? "200 OK" : "409 Conflict";
+            $rows=OC_DB::affected_rows();
+                       if(!OC_FILESYSTEM::file_exists($fspath) and $rows>0) {
+                               return "201 Created";
+                       }
+            return OC_DB::affected_rows($rows) ? "200 OK" : "409 Conflict";
     }
 
     /**
                  WHERE path = '$path'
                ";
             $res = OC_DB::select($query);
-        if ($res) {
+        if (is_array($res) and isset($res[0])) {
                                $row=$res[0];
-                OC_DB::free_result($res);
 
             if ($row) {
                 $result = array( "type"    => "write",
                                  "token"   => $row['token'],
                                  "created" => $row['created'],   
                                  "modified" => $row['modified'],   
-                                 "expires" => $row['expires']
+                                 "expires" => $row['expires'],
+                                 "recursive" => $row['recursive']
+                                 );
+            }
+        }else{
+                       //check for recursive locks;
+                       $query = "SELECT *
+                  FROM locks
+                 WHERE recursive = 1
+               ";
+            $res = OC_DB::select($query);
+            foreach($res as $row){
+                               if(strpos($path,$row['path'])==0){//are we a child of a folder with an recursive lock
+                                       $result = array( "type"    => "write",
+                                 "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
+                                 "depth"   => 0,
+                                 "owner"   => $row['owner'],
+                                 "token"   => $row['token'],
+                                 "created" => $row['created'],   
+                                 "modified" => $row['modified'],   
+                                 "expires" => $row['expires'],
+                                 "recursive" => $row['recursive']
                                  );
+                               }
             }
         }