[Pkg-owncloud-commits] [owncloud] 98/273: Also check for updated permissions for webdav storages

David Prévot taffit at moszumanska.debian.org
Fri Jul 4 03:13:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 6f5d5b9a307f0c3d4f751c5bd7b877757637b309
Author: Robin Appelman <icewind at owncloud.com>
Date:   Fri Jun 27 17:27:47 2014 +0200

    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 2771f97..f367415 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 64c6187..788ae41 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)) {
@@ -451,6 +437,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
 	 *
 	 * @param string $path
@@ -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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list