Also check for updated permissions for webdav storages

This commit is contained in:
Robin Appelman 2014-06-27 17:27:47 +02:00
parent 5b8c2ac750
commit 6f5d5b9a30
2 changed files with 54 additions and 17 deletions

View File

@ -33,6 +33,8 @@ class Storage extends DAV implements ISharedStorage {
*/ */
private $token; private $token;
private $updateChecked = false;
public function __construct($options) { public function __construct($options) {
$this->remote = $options['remote']; $this->remote = $options['remote'];
$this->remoteUser = $options['owner']; $this->remoteUser = $options['owner'];
@ -100,4 +102,20 @@ class Storage extends DAV implements ISharedStorage {
} }
return $this->scanner; return $this->scanner;
} }
/**
* check if a file or folder has been updated since $time
*
* @param string $path
* @param int $time
* @return bool
*/
public function hasUpdated($path, $time) {
// since we check updates for the entire storage at once, we only need to check once per request
if ($this->updateChecked) {
return false;
}
$this->updateChecked = true;
return parent::hasUpdated('', $time);
}
} }

View File

@ -426,8 +426,22 @@ class DAV extends \OC\Files\Storage\Common {
$this->init(); $this->init();
$response = $this->client->propfind($this->encodePath($path), array('{http://owncloud.org/ns}permissions')); $response = $this->client->propfind($this->encodePath($path), array('{http://owncloud.org/ns}permissions'));
if (isset($response['{http://owncloud.org/ns}permissions'])) { if (isset($response['{http://owncloud.org/ns}permissions'])) {
return $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
} else if ($this->is_dir($path)) {
return \OCP\PERMISSION_ALL;
} else if ($this->file_exists($path)) {
return \OCP\PERMISSION_ALL - \OCP\PERMISSION_CREATE;
} else {
return 0;
}
}
/**
* @param string $permissionsString
* @return int
*/
protected function parsePermissions($permissionsString) {
$permissions = \OCP\PERMISSION_READ; $permissions = \OCP\PERMISSION_READ;
$permissionsString = $response['{http://owncloud.org/ns}permissions'];
if (strpos($permissionsString, 'R') !== false) { if (strpos($permissionsString, 'R') !== false) {
$permissions |= \OCP\PERMISSION_SHARE; $permissions |= \OCP\PERMISSION_SHARE;
} }
@ -441,13 +455,6 @@ class DAV extends \OC\Files\Storage\Common {
$permissions |= \OCP\PERMISSION_CREATE; $permissions |= \OCP\PERMISSION_CREATE;
} }
return $permissions; return $permissions;
} else if ($this->is_dir($path)) {
return \OCP\PERMISSION_ALL;
} else if ($this->file_exists($path)) {
return \OCP\PERMISSION_ALL - \OCP\PERMISSION_CREATE;
} else {
return 0;
}
} }
/** /**
@ -459,10 +466,22 @@ class DAV extends \OC\Files\Storage\Common {
*/ */
public function hasUpdated($path, $time) { public function hasUpdated($path, $time) {
$this->init(); $this->init();
$response = $this->client->propfind($this->encodePath($path), array('{DAV:}getlastmodified', '{DAV:}getetag')); $response = $this->client->propfind($this->encodePath($path), array(
'{DAV:}getlastmodified',
'{DAV:}getetag',
'{http://owncloud.org/ns}permissions'
));
if (isset($response['{DAV:}getetag'])) { if (isset($response['{DAV:}getetag'])) {
$cachedData = $this->getCache()->get($path); $cachedData = $this->getCache()->get($path);
return $cachedData['etag'] !== $response['{DAV:}getetag']; $etag = trim($response['{DAV:}getetag'], '"');
if ($cachedData['etag'] !== $etag) {
return true;
} else if (isset($response['{http://owncloud.org/ns}permissions'])) {
$permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
return $permissions !== $cachedData['permissions'];
} else {
return false;
}
} else { } else {
$remoteMtime = strtotime($response['{DAV:}getlastmodified']); $remoteMtime = strtotime($response['{DAV:}getlastmodified']);
return $remoteMtime > $time; return $remoteMtime > $time;