[Pkg-owncloud-commits] [owncloud] 24/273: fix rebase, use 'object::user:<username>' or 'object::store:<storageid> as storage id, by default use container/bucket name for storageid, make storageid configurable, store user only for HomeObjectStoreStorage, change updateObject() to writeObject()

David Prévot taffit at moszumanska.debian.org
Fri Jul 4 03:12:54 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 f2fe00e972e2a592de99f49ad0d0c969ff287bc4
Author: Jörn Friedrich Dreyer <jfd at butonic.de>
Date:   Wed Jun 18 15:20:26 2014 +0200

    fix rebase, use 'object::user:<username>' or 'object::store:<storageid> as storage id, by default use container/bucket name for storageid, make storageid configurable, store user only for HomeObjectStoreStorage, change updateObject() to writeObject()
---
 .../files/objectstore/homeobjectstorestorage.php   | 37 ++++++++++++++++
 .../files/objectstore/objectstorestorage.php       | 50 +++++++---------------
 lib/private/files/objectstore/swift.php            |  5 ++-
 lib/public/files/objectstore/iobjectstore.php      |  9 +++-
 4 files changed, 63 insertions(+), 38 deletions(-)

diff --git a/lib/private/files/objectstore/homeobjectstorestorage.php b/lib/private/files/objectstore/homeobjectstorestorage.php
index 0c88972..26a2788 100644
--- a/lib/private/files/objectstore/homeobjectstorestorage.php
+++ b/lib/private/files/objectstore/homeobjectstorestorage.php
@@ -20,15 +20,52 @@
 
 namespace OC\Files\ObjectStore;
 
+use OC\User\User;
+
 class HomeObjectStoreStorage extends ObjectStoreStorage {
 
+	/**
+	 * The home user storage requires a user object to create a unique storage id
+	 * @param array $params
+	 */
 	public function __construct($params) {
+		if ( ! isset($params['user']) || ! $params['user'] instanceof User) {
+			throw new \Exception('missing user object in parameters');
+		}
+		$this->user = $params['user'];
 		parent::__construct($params);
 
+
 		//initialize cache with root directory in cache
 		if ( ! $this->is_dir('files') ) {
 			$this->mkdir('files');
 		}
 	}
 
+	public function getId () {
+		return 'object::user:' . $this->user->getUID();
+	}
+
+	/**
+	 * get the owner of a path
+	 *
+	 * @param string $path The path to get the owner
+	 * @return false|string uid
+	 */
+	public function getOwner($path) {
+		if (is_object($this->user)) {
+			return $this->user->getUID();
+		}
+		return false;
+	}
+
+	/**
+	 * @param string $path, optional
+	 * @return \OC\User\User
+	 */
+	public function getUser($path = null) {
+		return $this->user;
+	}
+
+
 }
\ No newline at end of file
diff --git a/lib/private/files/objectstore/objectstorestorage.php b/lib/private/files/objectstore/objectstorestorage.php
index 6b48e2d..b925f2e 100644
--- a/lib/private/files/objectstore/objectstorestorage.php
+++ b/lib/private/files/objectstore/objectstorestorage.php
@@ -40,16 +40,16 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
 	private static $tmpFiles = array();
 
 	public function __construct($params) {
-		if (isset($params['user']) && $params['user'] instanceof \OC\User\User) {
-			$this->user = $params['user'];
-		} else {
-			$this->user = null;
-		}
 		if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) {
 			$this->objectStore = $params['objectstore'];
 		} else {
 			throw new \Exception('missing IObjectStore instance');
 		}
+		if (isset($params['storageid'])) {
+			$this->id = 'object::store:'.$params['storageid'];
+		} else {
+			$this->id = 'object::store:'.$this->objectStore->getStorageId();
+		}
 		//initialize cache with root directory in cache
 		if ( ! $this->is_dir('/') ) {
 			$this->mkdir('/');
@@ -58,39 +58,22 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
 
 	/**
 	 * Object Stores use a NoopScanner because metadata is directly stored in
-	 * the file cache and cannot really scan the filesystem
+	 * the file cache and cannot really scan the filesystem. The storage passed in is not used anywhere.
 	 * @param string $path
+	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner
 	 * @return \OC\Files\ObjectStore\NoopScanner
 	 */
-	public function getScanner($path = '') {
+	public function getScanner($path = '', $storage = null) {
+		if (!$storage) {
+			$storage = $this;
+		}
 		if (!isset($this->scanner)) {
-			$this->scanner = new NoopScanner($this);
+			$this->scanner = new NoopScanner($storage);
 		}
 		return $this->scanner;
 	}
-	
-	/**
-	 * get the owner of a path
-	 *
-	 * @param string $path The path to get the owner
-	 * @return false|string uid
-	 */
-	public function getOwner($path) {
-		if (is_object($this->user)) {
-			return $this->user->getUID();
-		}
-		return false;
-	}
 
 	/**
-	 * @param string $path, optional
-	 * @return \OC\User\User
-	 */
-	public function getUser($path = null) {
-		return $this->user;
-	}
-	
-	/**
 	 * @param string $path
 	 * @return string
 	 */
@@ -107,10 +90,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
 	}
 
 	public function getId () {
-		if (is_object($this->user)) {
-			return 'objstore::user:' . $this->user->getUID();
-		}
-		return 'objstore::root';
+		return $this->id;
 	}
 
 	public function mkdir($path) {
@@ -363,7 +343,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
 			);
 			$fileId = $this->getCache()->put($path, $stat);
 			try {
-				$this->objectStore->updateObject($this->getURN($fileId));
+				$this->objectStore->writeObject($this->getURN($fileId));
 			} catch (\Exception $ex) {
 				$this->getCache()->remove($path);
 				\OCP\Util::writeLog('objectstore', 'Could not create object: '.$ex->getMessage(), \OCP\Util::ERROR);
@@ -411,7 +391,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
 		$fileId = $this->getCache()->put($path, $stat);
 		try {
 			//upload to object storage
-			$this->objectStore->updateObject($this->getURN($fileId), $tmpFile);
+			$this->objectStore->writeObject($this->getURN($fileId), $tmpFile);
 		} catch (\Exception $ex) {
 			$this->getCache()->remove($path);
 			\OCP\Util::writeLog('objectstore', 'Could not create object: '.$ex->getMessage(), \OCP\Util::ERROR);
diff --git a/lib/private/files/objectstore/swift.php b/lib/private/files/objectstore/swift.php
index f66b038..14892d2 100644
--- a/lib/private/files/objectstore/swift.php
+++ b/lib/private/files/objectstore/swift.php
@@ -80,6 +80,9 @@ class Swift implements \OCP\Files\ObjectStore\IObjectStore {
 		}
 	}
 
+	public function getStorageId() {
+		return $this->container->name;
+	}
 
 	/**
 	 * @param string $urn Unified Resource Name
@@ -87,7 +90,7 @@ class Swift implements \OCP\Files\ObjectStore\IObjectStore {
 	 * @return void
 	 * @throws Exception from openstack lib when something goes wrong
 	 */
-	public function updateObject($urn, $tmpFile = null) {
+	public function writeObject($urn, $tmpFile = null) {
 		$fileData = '';
 		if ($tmpFile) {
 			$fileData = fopen($tmpFile, 'r');
diff --git a/lib/public/files/objectstore/iobjectstore.php b/lib/public/files/objectstore/iobjectstore.php
index ecc35fa..3b6bd98 100644
--- a/lib/public/files/objectstore/iobjectstore.php
+++ b/lib/public/files/objectstore/iobjectstore.php
@@ -5,6 +5,11 @@ namespace OCP\Files\ObjectStore;
 interface IObjectStore {
 
 	/**
+	 * @return string the container or bucket name where objects are stored
+	 */
+	function getStorageId();
+
+	/**
 	 * @param string $urn the unified resource name used to identify the object
 	 * @param string $tmpFile path to the local temporary file that should be
 	 *        used to store the object
@@ -12,6 +17,7 @@ interface IObjectStore {
 	 * @throws Exception when something goes wrong, message will be logged
 	 */
 	function getObject($urn, $tmpFile);
+
 	/**
 	 * @param string $urn the unified resource name used to identify the object
 	 * @param string $tmpFile path to the local temporary file that the object
@@ -19,8 +25,7 @@ interface IObjectStore {
 	 * @return void
 	 * @throws Exception when something goes wrong, message will be logged
 	 */
-	function updateObject($urn, $tmpFile = null);
-
+	function writeObject($urn, $tmpFile = null);
 
 	/**
 	 * @param string $urn the unified resource name used to identify the object

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