[Pkg-owncloud-commits] [owncloud] 204/457: add locking to the view apo

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:06:06 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 bf7002bc655967dd8dd1970db45e5affce47c3c3
Author: Robin Appelman <icewind at owncloud.com>
Date:   Mon May 4 15:05:09 2015 +0200

    add locking to the view apo
---
 lib/private/files/view.php | 73 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 71 insertions(+), 2 deletions(-)

diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 63af2b6..c82f8e1 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -47,6 +47,7 @@ use OCP\Files\FileNameTooLongException;
 use OCP\Files\InvalidCharacterInPathException;
 use OCP\Files\InvalidPathException;
 use OCP\Files\ReservedWordException;
+use OCP\Lock\ILockingProvider;
 
 /**
  * Class to provide access to ownCloud filesystem via a "view", and methods for
@@ -72,6 +73,11 @@ class View {
 	protected $updater;
 
 	/**
+	 * @var \OCP\Lock\ILockingProvider
+	 */
+	private $lockingProvider;
+
+	/**
 	 * @param string $root
 	 * @throws \Exception If $root contains an invalid path
 	 */
@@ -79,12 +85,13 @@ class View {
 		if (is_null($root)) {
 			throw new \InvalidArgumentException('Root can\'t be null');
 		}
-		if(!Filesystem::isValidPath($root)) {
+		if (!Filesystem::isValidPath($root)) {
 			throw new \Exception();
 		}
 
 		$this->fakeRoot = $root;
 		$this->updater = new Updater($this);
+		$this->lockingProvider = \OC::$server->getLockingProvider();
 	}
 
 	public function getAbsolutePath($path = '/') {
@@ -137,7 +144,7 @@ class View {
 			return $path;
 		}
 
-		if (rtrim($path,'/') === rtrim($this->fakeRoot, '/')) {
+		if (rtrim($path, '/') === rtrim($this->fakeRoot, '/')) {
 			return '/';
 		}
 
@@ -1553,4 +1560,66 @@ class View {
 			throw new InvalidPathException($l10n->t('File name is too long'));
 		}
 	}
+
+	/**
+	 * get all parent folders of $path
+	 *
+	 * @param string $path
+	 * @return string[]
+	 */
+	private function getParents($path) {
+		$parts = explode('/', $path);
+
+		// remove the singe file
+		array_pop($parts);
+		$result = array('/');
+		$resultPath = '';
+		foreach ($parts as $part) {
+			if ($part) {
+				$resultPath .= '/' . $part;
+				$result[] = $resultPath;
+			}
+		}
+		return $result;
+	}
+
+	private function lockPath($path, $type) {
+		$mount = $this->getMount($path);
+		$mount->getStorage()->acquireLock($mount->getInternalPath($path), $type, $this->lockingProvider);
+	}
+
+	private function unlockPath($path, $type) {
+		$mount = $this->getMount($path);
+		$mount->getStorage()->releaseLock($mount->getInternalPath($path), $type, $this->lockingProvider);
+	}
+
+	/**
+	 * Lock a path and all it's parents
+	 *
+	 * @param string $path
+	 * @param int $type
+	 */
+	public function lockFile($path, $type) {
+		$this->lockPath($path, $type);
+
+		$parents = $this->getParents($path);
+		foreach ($parents as $parent) {
+			$this->lockPath($parent, ILockingProvider::LOCK_SHARED);
+		}
+	}
+
+	/**
+	 * Unlock a path and all it's parents
+	 *
+	 * @param string $path
+	 * @param int $type
+	 */
+	public function unlockFile($path, $type) {
+		$this->unlockPath($path, $type);
+
+		$parents = $this->getParents($path);
+		foreach ($parents as $parent) {
+			$this->unlockPath($parent, ILockingProvider::LOCK_SHARED);
+		}
+	}
 }

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