mayor improvements in the handling of locks in webdav
This commit is contained in:
parent
d374bcddc1
commit
3d2f68c43f
1 changed files with 70 additions and 18 deletions
|
@ -323,7 +323,6 @@
|
||||||
function PUT(&$options)
|
function PUT(&$options)
|
||||||
{
|
{
|
||||||
$fspath = $options["path"];
|
$fspath = $options["path"];
|
||||||
|
|
||||||
$dir = dirname($fspath);
|
$dir = dirname($fspath);
|
||||||
if (!OC_FILESYSTEM::file_exists($dir) || !OC_FILESYSTEM::is_dir($dir)) {
|
if (!OC_FILESYSTEM::file_exists($dir) || !OC_FILESYSTEM::is_dir($dir)) {
|
||||||
return "409 Conflict"; // TODO right status code for both?
|
return "409 Conflict"; // TODO right status code for both?
|
||||||
|
@ -394,7 +393,14 @@
|
||||||
if (!OC_FILESYSTEM::file_exists($path)) {
|
if (!OC_FILESYSTEM::file_exists($path)) {
|
||||||
return "404 Not found";
|
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)) {
|
if (OC_FILESYSTEM::is_dir($path)) {
|
||||||
$query = "DELETE FROM properties WHERE path LIKE '".$this->_slashify($options["path"])."%'";
|
$query = "DELETE FROM properties WHERE path LIKE '".$this->_slashify($options["path"])."%'";
|
||||||
OC_DB::query($query);
|
OC_DB::query($query);
|
||||||
|
@ -593,11 +599,19 @@
|
||||||
{
|
{
|
||||||
// get absolute fs path to requested resource
|
// get absolute fs path to requested resource
|
||||||
$fspath = $options["path"];
|
$fspath = $options["path"];
|
||||||
|
|
||||||
// TODO recursive locks on directories not supported yet
|
// TODO recursive locks on directories not supported yet
|
||||||
// makes litmus test "32. lock_collection" fail
|
// makes litmus test "32. lock_collection" fail
|
||||||
if (is_dir($fspath) && !empty($options["depth"])) {
|
if (OC_FILESYSTEM::is_dir($fspath) && !empty($options["depth"])) {
|
||||||
return "409 Conflict";
|
switch($options["depth"]){
|
||||||
|
case 'infinity':
|
||||||
|
$recursion=1;
|
||||||
|
break;
|
||||||
|
case '0':
|
||||||
|
$recursion=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$recursion=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$options["timeout"] = time()+300; // 5min. hardcoded
|
$options["timeout"] = time()+300; // 5min. hardcoded
|
||||||
|
@ -606,11 +620,10 @@
|
||||||
$where = "WHERE path = '$options[path]' AND token = '$options[update]'";
|
$where = "WHERE path = '$options[path]' AND token = '$options[update]'";
|
||||||
|
|
||||||
$query = "SELECT owner, exclusivelock FROM locks $where";
|
$query = "SELECT owner, exclusivelock FROM locks $where";
|
||||||
$res = OC_DB::query($query);
|
$res = OC_DB::select($query);
|
||||||
$row = OC_DB::fetch_assoc($res);
|
|
||||||
OC_DB::free_result($res);
|
|
||||||
|
|
||||||
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";
|
$query = "UPDATE `locks` SET `expires` = '$options[timeout]', `modified` = ".time()." $where";
|
||||||
OC_DB::query($query);
|
OC_DB::query($query);
|
||||||
|
|
||||||
|
@ -619,8 +632,23 @@
|
||||||
$options['type'] = $row["exclusivelock"] ? "write" : "read";
|
$options['type'] = $row["exclusivelock"] ? "write" : "read";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {//check for indirect refresh
|
||||||
return false;
|
$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,11 +659,14 @@
|
||||||
, `modified` = ".time()."
|
, `modified` = ".time()."
|
||||||
, `owner` = '$options[owner]'
|
, `owner` = '$options[owner]'
|
||||||
, `expires` = '$options[timeout]'
|
, `expires` = '$options[timeout]'
|
||||||
, `exclusivelock` = " .($options['scope'] === "exclusive" ? "1" : "0")
|
, `exclusivelock` = " .($options['scope'] === "exclusive" ? "1" : "0")."
|
||||||
;
|
, `recursive` = $recursion";
|
||||||
OC_DB::query($query);
|
OC_DB::query($query);
|
||||||
|
$rows=OC_DB::affected_rows();
|
||||||
return OC_DB::affected_rows() ? "200 OK" : "409 Conflict";
|
if(!OC_FILESYSTEM::file_exists($fspath) and $rows>0) {
|
||||||
|
return "201 Created";
|
||||||
|
}
|
||||||
|
return OC_DB::affected_rows($rows) ? "200 OK" : "409 Conflict";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -668,9 +699,8 @@
|
||||||
WHERE path = '$path'
|
WHERE path = '$path'
|
||||||
";
|
";
|
||||||
$res = OC_DB::select($query);
|
$res = OC_DB::select($query);
|
||||||
if ($res) {
|
if (is_array($res) and isset($res[0])) {
|
||||||
$row=$res[0];
|
$row=$res[0];
|
||||||
OC_DB::free_result($res);
|
|
||||||
|
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$result = array( "type" => "write",
|
$result = array( "type" => "write",
|
||||||
|
@ -680,9 +710,31 @@
|
||||||
"token" => $row['token'],
|
"token" => $row['token'],
|
||||||
"created" => $row['created'],
|
"created" => $row['created'],
|
||||||
"modified" => $row['modified'],
|
"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']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
Loading…
Reference in a new issue