From 5b8c2ac750e79e574b49e0ba7ac866f0d5002003 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 27 Jun 2014 17:10:46 +0200 Subject: [PATCH 1/4] Use the etag to check for updates in webdav storages where available --- lib/private/files/storage/dav.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/private/files/storage/dav.php b/lib/private/files/storage/dav.php index 8536c65ace..64c61873d0 100644 --- a/lib/private/files/storage/dav.php +++ b/lib/private/files/storage/dav.php @@ -449,5 +449,24 @@ class DAV extends \OC\Files\Storage\Common { return 0; } } + + /** + * check if a file or folder has been updated since $time + * + * @param string $path + * @param int $time + * @return bool + */ + public function hasUpdated($path, $time) { + $this->init(); + $response = $this->client->propfind($this->encodePath($path), array('{DAV:}getlastmodified', '{DAV:}getetag')); + if (isset($response['{DAV:}getetag'])) { + $cachedData = $this->getCache()->get($path); + return $cachedData['etag'] !== $response['{DAV:}getetag']; + } else { + $remoteMtime = strtotime($response['{DAV:}getlastmodified']); + return $remoteMtime > $time; + } + } } From 6f5d5b9a307f0c3d4f751c5bd7b877757637b309 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 27 Jun 2014 17:27:47 +0200 Subject: [PATCH 2/4] Also check for updated permissions for webdav storages --- apps/files_sharing/lib/external/storage.php | 18 +++++++ lib/private/files/storage/dav.php | 53 ++++++++++++++------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 2771f97461..f367415579 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -33,6 +33,8 @@ class Storage extends DAV implements ISharedStorage { */ private $token; + private $updateChecked = false; + public function __construct($options) { $this->remote = $options['remote']; $this->remoteUser = $options['owner']; @@ -100,4 +102,20 @@ class Storage extends DAV implements ISharedStorage { } 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); + } } diff --git a/lib/private/files/storage/dav.php b/lib/private/files/storage/dav.php index 64c61873d0..788ae41e2b 100644 --- a/lib/private/files/storage/dav.php +++ b/lib/private/files/storage/dav.php @@ -426,21 +426,7 @@ class DAV extends \OC\Files\Storage\Common { $this->init(); $response = $this->client->propfind($this->encodePath($path), array('{http://owncloud.org/ns}permissions')); if (isset($response['{http://owncloud.org/ns}permissions'])) { - $permissions = \OCP\PERMISSION_READ; - $permissionsString = $response['{http://owncloud.org/ns}permissions']; - if (strpos($permissionsString, 'R') !== false) { - $permissions |= \OCP\PERMISSION_SHARE; - } - if (strpos($permissionsString, 'D') !== false) { - $permissions |= \OCP\PERMISSION_DELETE; - } - if (strpos($permissionsString, 'W') !== false) { - $permissions |= \OCP\PERMISSION_UPDATE; - } - if (strpos($permissionsString, 'C') !== false) { - $permissions |= \OCP\PERMISSION_CREATE; - } - return $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)) { @@ -450,6 +436,27 @@ class DAV extends \OC\Files\Storage\Common { } } + /** + * @param string $permissionsString + * @return int + */ + protected function parsePermissions($permissionsString) { + $permissions = \OCP\PERMISSION_READ; + if (strpos($permissionsString, 'R') !== false) { + $permissions |= \OCP\PERMISSION_SHARE; + } + if (strpos($permissionsString, 'D') !== false) { + $permissions |= \OCP\PERMISSION_DELETE; + } + if (strpos($permissionsString, 'W') !== false) { + $permissions |= \OCP\PERMISSION_UPDATE; + } + if (strpos($permissionsString, 'C') !== false) { + $permissions |= \OCP\PERMISSION_CREATE; + } + return $permissions; + } + /** * check if a file or folder has been updated since $time * @@ -459,10 +466,22 @@ class DAV extends \OC\Files\Storage\Common { */ public function hasUpdated($path, $time) { $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'])) { $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 { $remoteMtime = strtotime($response['{DAV:}getlastmodified']); return $remoteMtime > $time; From db3f0cee4ad140f69d976727f33452c796a67288 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 27 Jun 2014 17:28:56 +0200 Subject: [PATCH 3/4] Fix parsing of webdav permissions --- lib/private/files/storage/dav.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/private/files/storage/dav.php b/lib/private/files/storage/dav.php index 788ae41e2b..8b97f75020 100644 --- a/lib/private/files/storage/dav.php +++ b/lib/private/files/storage/dav.php @@ -451,8 +451,9 @@ class DAV extends \OC\Files\Storage\Common { if (strpos($permissionsString, 'W') !== false) { $permissions |= \OCP\PERMISSION_UPDATE; } - if (strpos($permissionsString, 'C') !== false) { + if (strpos($permissionsString, 'CK') !== false) { $permissions |= \OCP\PERMISSION_CREATE; + $permissions |= \OCP\PERMISSION_UPDATE; } return $permissions; } From 1bb1504d2452ccf1fde24700d11dd105805d762d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 27 Jun 2014 17:31:51 +0200 Subject: [PATCH 4/4] Improve comment --- apps/files_sharing/lib/external/storage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index f367415579..454196f15a 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -111,7 +111,8 @@ class Storage extends DAV implements ISharedStorage { * @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 + // since for owncloud webdav servers we can rely on etag propagation we only need to check the root of the storage + // because of that we only do one check for the entire storage per request if ($this->updateChecked) { return false; }