[Pkg-owncloud-commits] [owncloud] 386/457: Only lock files in data/username/files/

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:06:52 UTC 2015


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

taffit pushed a commit to branch stable8
in repository owncloud.

commit caf16b083e3abaea18a05fe5f923bd306c09ac6b
Author: Joas Schilling <nickvergessen at owncloud.com>
Date:   Thu Jun 11 16:11:16 2015 +0200

    Only lock files in data/username/files/
---
 lib/private/files/view.php | 62 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 53 insertions(+), 9 deletions(-)

diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index b98842f..7bb4a2b 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -1663,12 +1663,15 @@ class View {
 	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
 	 */
 	private function lockPath($path, $type) {
+		$absolutePath = $this->getAbsolutePath($path);
+		if (!$this->shouldLockFile($absolutePath)) {
+			return;
+		}
+
 		$mount = $this->getMount($path);
 		if ($mount) {
 			$mount->getStorage()->acquireLock(
-				$mount->getInternalPath(
-					$this->getAbsolutePath($path)
-				),
+				$mount->getInternalPath($absolutePath),
 				$type,
 				$this->lockingProvider
 			);
@@ -1680,12 +1683,15 @@ class View {
 	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
 	 */
 	private function changeLock($path, $type) {
+		$absolutePath = $this->getAbsolutePath($path);
+		if (!$this->shouldLockFile($absolutePath)) {
+			return;
+		}
+
 		$mount = $this->getMount($path);
 		if ($mount) {
 			$mount->getStorage()->changeLock(
-				$mount->getInternalPath(
-					$this->getAbsolutePath($path)
-				),
+				$mount->getInternalPath($absolutePath),
 				$type,
 				$this->lockingProvider
 			);
@@ -1697,12 +1703,15 @@ class View {
 	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
 	 */
 	private function unlockPath($path, $type) {
+		$absolutePath = $this->getAbsolutePath($path);
+		if (!$this->shouldLockFile($absolutePath)) {
+			return;
+		}
+
 		$mount = $this->getMount($path);
 		if ($mount) {
 			$mount->getStorage()->releaseLock(
-				$mount->getInternalPath(
-					$this->getAbsolutePath($path)
-				),
+				$mount->getInternalPath($absolutePath),
 				$type,
 				$this->lockingProvider
 			);
@@ -1717,6 +1726,12 @@ class View {
 	 */
 	public function lockFile($path, $type) {
 		$path = '/' . trim($path, '/');
+
+		$absolutePath = $this->getAbsolutePath($path);
+		if (!$this->shouldLockFile($absolutePath)) {
+			return;
+		}
+
 		$this->lockPath($path, $type);
 
 		$parents = $this->getParents($path);
@@ -1733,6 +1748,12 @@ class View {
 	 */
 	public function unlockFile($path, $type) {
 		$path = rtrim($path, '/');
+
+		$absolutePath = $this->getAbsolutePath($path);
+		if (!$this->shouldLockFile($absolutePath)) {
+			return;
+		}
+
 		$this->unlockPath($path, $type);
 
 		$parents = $this->getParents($path);
@@ -1740,4 +1761,27 @@ class View {
 			$this->unlockPath($parent, ILockingProvider::LOCK_SHARED);
 		}
 	}
+
+	/**
+	 * Only lock files in data/user/files/
+	 *
+	 * @param string $path Absolute path to the file/folder we try to (un)lock
+	 * @return bool
+	 */
+	protected function shouldLockFile($path) {
+		$path = Filesystem::normalizePath($path);
+
+		if (substr_count($path, '/') >= 3) {
+			// E.g.: /username/files/path-to-file
+			$pathSegments = explode('/', $path, 4);
+			return $pathSegments[2] === 'files';
+
+		} else if (substr_count($path, '/') === 2) {
+			// E.g.: /username/files
+			$pathSegments = explode('/', $path, 3);
+			return $pathSegments[2] === 'files';
+		}
+
+		return true;
+	}
 }

-- 
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