summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-06-27 16:53:03 +0200
committerVincent Petry <pvince81@owncloud.com>2014-06-27 16:53:03 +0200
commitfd8b5680dd826cf98df3b11b3a079dc70147a2c0 (patch)
tree9e5df78df804b54e909b550089432647fc4d7346 /lib
parent3b2fd5e4e6aad769f656c473f1a1fe53f5936c47 (diff)
parent25dbbbadd33ad1f859498ff8c6ba16091959bce4 (diff)
downloadnextcloud-server-fd8b5680dd826cf98df3b11b3a079dc70147a2c0.tar.gz
nextcloud-server-fd8b5680dd826cf98df3b11b3a079dc70147a2c0.zip
Merge pull request #8383 from owncloud/object_storage
Object storage
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/filesystem.php31
-rw-r--r--lib/private/files/mount/mount.php7
-rw-r--r--lib/private/files/objectstore/homeobjectstorestorage.php71
-rw-r--r--lib/private/files/objectstore/noopscanner.php74
-rw-r--r--lib/private/files/objectstore/objectstorestorage.php421
-rw-r--r--lib/private/files/objectstore/swift.php147
-rw-r--r--lib/private/files/storage/common.php5
-rwxr-xr-xlib/private/util.php82
-rw-r--r--lib/public/files/objectstore/iobjectstore.php33
9 files changed, 849 insertions, 22 deletions
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index 2cc4a2130eb..4774d25ad9e 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -325,13 +325,36 @@ class Filesystem {
$userObject = \OC_User::getManager()->get($user);
if (!is_null($userObject)) {
+ $homeStorage = \OC_Config::getValue( 'objectstore' );
+ if (!empty($homeStorage)) {
+ // sanity checks
+ if (empty($homeStorage['class'])) {
+ \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
+ }
+ if (!isset($homeStorage['arguments'])) {
+ $homeStorage['arguments'] = array();
+ }
+ // instantiate object store implementation
+ $homeStorage['arguments']['objectstore'] = new $homeStorage['class']($homeStorage['arguments']);
+ // mount with home object store implementation
+ $homeStorage['class'] = '\OC\Files\ObjectStore\HomeObjectStoreStorage';
+ } else {
+ $homeStorage = array(
+ //default home storage configuration:
+ 'class' => '\OC\Files\Storage\Home',
+ 'arguments' => array()
+ );
+ }
+ $homeStorage['arguments']['user'] = $userObject;
+
// check for legacy home id (<= 5.0.12)
if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) {
- self::mount('\OC\Files\Storage\Home', array('user' => $userObject, 'legacy' => true), $user);
- }
- else {
- self::mount('\OC\Files\Storage\Home', array('user' => $userObject), $user);
+ $homeStorage['arguments']['legacy'] = true;
}
+
+ self::mount($homeStorage['class'], $homeStorage['arguments'], $user);
+
+ $home = \OC\Files\Filesystem::getStorage($user);
}
else {
self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user);
diff --git a/lib/private/files/mount/mount.php b/lib/private/files/mount/mount.php
index 04bccbcab87..48c9d88c23c 100644
--- a/lib/private/files/mount/mount.php
+++ b/lib/private/files/mount/mount.php
@@ -93,7 +93,12 @@ class Mount {
try {
return $this->loader->load($this->mountPoint, $this->class, $this->arguments);
} catch (\Exception $exception) {
- \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR);
+ if ($this->mountPoint === '/') {
+ // the root storage could not be initialized, show the user!
+ throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
+ } else {
+ \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR);
+ }
return null;
}
} else {
diff --git a/lib/private/files/objectstore/homeobjectstorestorage.php b/lib/private/files/objectstore/homeobjectstorestorage.php
new file mode 100644
index 00000000000..26a2788d860
--- /dev/null
+++ b/lib/private/files/objectstore/homeobjectstorestorage.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * @author Jörn Friedrich Dreyer
+ * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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/noopscanner.php b/lib/private/files/objectstore/noopscanner.php
new file mode 100644
index 00000000000..59ca1771971
--- /dev/null
+++ b/lib/private/files/objectstore/noopscanner.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * @author Jörn Friedrich Dreyer
+ * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Files\ObjectStore;
+use \OC\Files\Cache\Scanner;
+use \OC\Files\Storage\Storage;
+
+class NoopScanner extends Scanner {
+
+ public function __construct(Storage $storage) {
+ //we don't need the storage, so do nothing here
+ }
+
+ /**
+ * scan a single file and store it in the cache
+ *
+ * @param string $file
+ * @param int $reuseExisting
+ * @param bool $parentExistsInCache
+ * @return array with metadata of the scanned file
+ */
+ public function scanFile($file, $reuseExisting = 0, $parentExistsInCache = false) {
+ return array();
+ }
+
+ /**
+ * scan a folder and all it's children
+ *
+ * @param string $path
+ * @param bool $recursive
+ * @param int $reuse
+ * @return array with the meta data of the scanned file or folder
+ */
+ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) {
+ return array();
+ }
+
+ /**
+ * scan all the files and folders in a folder
+ *
+ * @param string $path
+ * @param bool $recursive
+ * @param int $reuse
+ * @return int the size of the scanned folder or -1 if the size is unknown at this stage
+ */
+ public function scanChildren($path, $recursive = Storage::SCAN_RECURSIVE, $reuse = -1) {
+ $size = 0;
+ return $size;
+ }
+
+ /**
+ * walk over any folders that are not fully scanned yet and scan them
+ */
+ public function backgroundScan() {
+ //noop
+ }
+}
diff --git a/lib/private/files/objectstore/objectstorestorage.php b/lib/private/files/objectstore/objectstorestorage.php
new file mode 100644
index 00000000000..85f43b90cbb
--- /dev/null
+++ b/lib/private/files/objectstore/objectstorestorage.php
@@ -0,0 +1,421 @@
+<?php
+/**
+ * @author Jörn Friedrich Dreyer
+ * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Files\ObjectStore;
+
+use OC\Files\Filesystem;
+use OCP\Files\ObjectStore\IObjectStore;
+
+class ObjectStoreStorage extends \OC\Files\Storage\Common {
+
+ /**
+ * @var array
+ */
+ private static $tmpFiles = array();
+ /**
+ * @var \OCP\Files\ObjectStore\IObjectStore $objectStore
+ */
+ protected $objectStore;
+ /**
+ * @var \OC\User\User $user
+ */
+ protected $user;
+
+ public function __construct($params) {
+ 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('/');
+ }
+ }
+
+ public function mkdir($path) {
+ $path = $this->normalizePath($path);
+
+ if ($this->is_dir($path)) {
+ return false;
+ }
+
+ $dirName = $this->normalizePath(dirname($path));
+ $parentExists = $this->is_dir($dirName);
+
+ $mTime = time();
+
+ $data = array(
+ 'mimetype' => 'httpd/unix-directory',
+ 'size' => 0,
+ 'mtime' => $mTime,
+ 'storage_mtime' => $mTime,
+ 'permissions' => \OCP\PERMISSION_ALL,
+ );
+
+ if ($dirName === '' && !$parentExists) {
+ //create root on the fly
+ $data['etag'] = $this->getETag('');
+ $this->getCache()->put('', $data);
+ $parentExists = true;
+
+ // we are done when the root folder was meant to be created
+ if ($dirName === $path) {
+ return true;
+ }
+ }
+
+ if ($parentExists) {
+ $data['etag'] = $this->getETag($path);
+ $this->getCache()->put($path, $data);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param string $path
+ * @return string
+ */
+ private function normalizePath($path) {
+ $path = trim($path, '/');
+ //FIXME why do we sometimes get a path like 'files//username'?
+ $path = str_replace('//', '/', $path);
+
+ // dirname('/folder') returns '.' but internally (in the cache) we store the root as ''
+ if (!$path || $path === '.') {
+ $path = '';
+ }
+
+ return $path;
+ }
+
+ /**
+ * Object Stores use a NoopScanner because metadata is directly stored in
+ * 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 = '', $storage = null) {
+ if (!$storage) {
+ $storage = $this;
+ }
+ if (!isset($this->scanner)) {
+ $this->scanner = new NoopScanner($storage);
+ }
+ return $this->scanner;
+ }
+
+ public function getId() {
+ return $this->id;
+ }
+
+ public function rmdir($path) {
+ $path = $this->normalizePath($path);
+
+ if (!$this->is_dir($path)) {
+ return false;
+ }
+
+ $this->rmObjects($path);
+
+ $this->getCache()->remove($path);
+
+ return true;
+ }
+
+ private function rmObjects($path) {
+ $children = $this->getCache()->getFolderContents($path);
+ foreach ($children as $child) {
+ if ($child['mimetype'] === 'httpd/unix-directory') {
+ $this->rmObjects($child['path']);
+ } else {
+ $this->unlink($child['path']);
+ }
+ }
+ }
+
+ public function unlink($path) {
+ $path = $this->normalizePath($path);
+ $stat = $this->stat($path);
+
+ if ($stat && isset($stat['fileid'])) {
+ if ($stat['mimetype'] === 'httpd/unix-directory') {
+ return $this->rmdir($path);
+ }
+ try {
+ $this->objectStore->deleteObject($this->getURN($stat['fileid']));
+ } catch (\Exception $ex) {
+ if ($ex->getCode() !== 404) {
+ \OCP\Util::writeLog('objectstore', 'Could not delete object: ' . $ex->getMessage(), \OCP\Util::ERROR);
+ return false;
+ } else {
+ //removing from cache is ok as it does not exist in the objectstore anyway
+ }
+ }
+ $this->getCache()->remove($path);
+ return true;
+ }
+ return false;
+ }
+
+ public function stat($path) {
+ $path = $this->normalizePath($path);
+ return $this->getCache()->get($path);
+ }
+
+ /**
+ * Override this method if you need a different unique resource identifier for your object storage implementation.
+ * The default implementations just appends the fileId to 'urn:oid:'. Make sure the URN is unique over all users.
+ * You may need a mapping table to store your URN if it cannot be generated from the fileid.
+ *
+ * @param int $fileId the fileid
+ * @return null|string the unified resource name used to identify the object
+ */
+ protected function getURN($fileId) {
+ if (is_numeric($fileId)) {
+ return 'urn:oid:' . $fileId;
+ }
+ return null;
+ }
+
+ public function opendir($path) {
+ $path = $this->normalizePath($path);
+
+ try {
+ $files = array();
+ $folderContents = $this->getCache()->getFolderContents($path);
+ foreach ($folderContents as $file) {
+ $files[] = $file['name'];
+ }
+
+ \OC\Files\Stream\Dir::register('objectstore' . $path . '/', $files);
+
+ return opendir('fakedir://objectstore' . $path . '/');
+ } catch (Exception $e) {
+ \OCP\Util::writeLog('objectstore', $e->getMessage(), \OCP\Util::ERROR);
+ return false;
+ }
+ }
+
+ public function filetype($path) {
+ $path = $this->normalizePath($path);
+ $stat = $this->stat($path);
+ if ($stat) {
+ if ($stat['mimetype'] === 'httpd/unix-directory') {
+ return 'dir';
+ }
+ return 'file';
+ } else {
+ return false;
+ }
+ }
+
+ public function fopen($path, $mode) {
+ $path = $this->normalizePath($path);
+
+ switch ($mode) {
+ case 'r':
+ case 'rb':
+ $stat = $this->stat($path);
+ if (is_array($stat)) {
+ try {
+ return $this->objectStore->readObject($this->getURN($stat['fileid']));
+ } catch (\Exception $ex) {
+ \OCP\Util::writeLog('objectstore', 'Could not get object: ' . $ex->getMessage(), \OCP\Util::ERROR);
+ return false;
+ }
+ } else {
+ return false;
+ }
+ case 'w':
+ case 'wb':
+ case 'a':
+ case 'ab':
+ case 'r+':
+ case 'w+':
+ case 'wb+':
+ case 'a+':
+ case 'x':
+ case 'x+':
+ case 'c':
+ case 'c+':
+ if (strrpos($path, '.') !== false) {
+ $ext = substr($path, strrpos($path, '.'));
+ } else {
+ $ext = '';
+ }
+ $tmpFile = \OC_Helper::tmpFile($ext);
+ \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
+ if ($this->file_exists($path)) {
+ $source = $this->fopen($path, 'r');
+ file_put_contents($tmpFile, $source);
+ }
+ self::$tmpFiles[$tmpFile] = $path;
+
+ return fopen('close://' . $tmpFile, $mode);
+ }
+ return false;
+ }
+
+ public function file_exists($path) {
+ $path = $this->normalizePath($path);
+ return (bool)$this->stat($path);
+ }
+
+ public function rename($source, $target) {
+ $source = $this->normalizePath($source);
+ $target = $this->normalizePath($target);
+ $stat1 = $this->stat($source);
+ if (isset($stat1['mimetype']) && $stat1['mimetype'] === 'httpd/unix-directory') {
+ $this->remove($target);
+ $dir = $this->opendir($source);
+ $this->mkdir($target);
+ while ($file = readdir($dir)) {
+ if (!Filesystem::isIgnoredDir($file)) {
+ if (!$this->rename($source . '/' . $file, $target . '/' . $file)) {
+ return false;
+ }
+ }
+ }
+ closedir($dir);
+ $this->remove($source);
+ return true;
+ } else {
+ if (is_array($stat1)) {
+ $parent = $this->stat(dirname($target));
+ if (is_array($parent)) {
+ $this->remove($target);
+ $stat1['parent'] = $parent['fileid'];
+ $stat1['path'] = $target;
+ $stat1['path_hash'] = md5($target);
+ $stat1['name'] = \OC_Util::basename($target);
+ $stat1['mtime'] = time();
+ $stat1['etag'] = $this->getETag($target);
+ $this->getCache()->update($stat1['fileid'], $stat1);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public function getMimeType($path) {
+ $path = $this->normalizePath($path);
+ $stat = $this->stat($path);
+ if (is_array($stat)) {
+ return $stat['mimetype'];
+ } else {
+ return false;
+ }
+ }
+
+ public function touch($path, $mtime = null) {
+ if (is_null($mtime)) {
+ $mtime = time();
+ }
+
+ $path = $this->normalizePath($path);
+ $dirName = dirname($path);
+ $parentExists = $this->is_dir($dirName);
+ if (!$parentExists) {
+ return false;
+ }
+
+ $stat = $this->stat($path);
+ if (is_array($stat)) {
+ // update existing mtime in db
+ $stat['mtime'] = $mtime;
+ $this->getCache()->update($stat['fileid'], $stat);
+ } else {
+ $mimeType = \OC_Helper::getFileNameMimeType($path);
+ // create new file
+ $stat = array(
+ 'etag' => $this->getETag($path),
+ 'mimetype' => $mimeType,
+ 'size' => 0,
+ 'mtime' => $mtime,
+ 'storage_mtime' => $mtime,
+ 'permissions' => \OCP\PERMISSION_ALL,
+ );
+ $fileId = $this->getCache()->put($path, $stat);
+ try {
+ //read an empty file from memory
+ $this->objectStore->writeObject($this->getURN($fileId), fopen('php://memory', 'r'));
+ } catch (\Exception $ex) {
+ $this->getCache()->remove($path);
+ \OCP\Util::writeLog('objectstore', 'Could not create object: ' . $ex->getMessage(), \OCP\Util::ERROR);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public function writeBack($tmpFile) {
+ if (!isset(self::$tmpFiles[$tmpFile])) {
+ return false;
+ }
+
+ $path = self::$tmpFiles[$tmpFile];
+ $stat = $this->stat($path);
+ if (empty($stat)) {
+ // create new file
+ $stat = array(
+ 'etag' => $this->getETag($path),
+ 'permissions' => \OCP\PERMISSION_ALL,
+ );
+ }
+ // update stat with new data
+ $mTime = time();
+ $stat['size'] = filesize($tmpFile);
+ $stat['mtime'] = $mTime;
+ $stat['storage_mtime'] = $mTime;
+ $stat['mimetype'] = \OC_Helper::getMimeType($tmpFile);
+
+ $fileId = $this->getCache()->put($path, $stat);
+ try {
+ //upload to object storage
+ $this->objectStore->writeObject($this->getURN($fileId), fopen($tmpFile, 'r'));
+ } catch (\Exception $ex) {
+ $this->getCache()->remove($path);
+ \OCP\Util::writeLog('objectstore', 'Could not create object: ' . $ex->getMessage(), \OCP\Util::ERROR);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * external changes are not supported, exclusive access to the object storage is assumed
+ *
+ * @param string $path
+ * @param int $time
+ * @return false
+ */
+ public function hasUpdated($path, $time) {
+ return false;
+ }
+}
diff --git a/lib/private/files/objectstore/swift.php b/lib/private/files/objectstore/swift.php
new file mode 100644
index 00000000000..3378fd7b86f
--- /dev/null
+++ b/lib/private/files/objectstore/swift.php
@@ -0,0 +1,147 @@
+<?php
+/**
+ * @author Jörn Friedrich Dreyer
+ * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Files\ObjectStore;
+
+use Guzzle\Http\Exception\ClientErrorResponseException;
+use OCP\Files\ObjectStore\IObjectStore;
+use OpenCloud\OpenStack;
+use OpenCloud\Rackspace;
+
+class Swift implements IObjectStore {
+ /**
+ * @var \OpenCloud\OpenStack
+ */
+ private $client;
+
+ /**
+ * @var array
+ */
+ private $params;
+
+ /**
+ * @var \OpenCloud\ObjectStore\Service
+ */
+ private $objectStoreService;
+
+ /**
+ * @var \OpenCloud\ObjectStore\Resource\Container
+ */
+ private $container;
+
+ public function __construct($params) {
+ if (!isset($params['container'])) {
+ $params['container'] = 'owncloud';
+ }
+ if (!isset($params['autocreate'])) {
+ // should only be true for tests
+ $params['autocreate'] = false;
+ }
+
+ if (isset($params['apiKey'])) {
+ $this->client = new Rackspace($params['url'], $params);
+ } else {
+ $this->client = new OpenStack($params['url'], $params);
+ }
+ $this->params = $params;
+ }
+
+ protected function init() {
+ if ($this->container) {
+ return;
+ }
+
+ // the OpenCloud client library will default to 'cloudFiles' if $serviceName is null
+ $serviceName = null;
+ if ($this->params['serviceName']) {
+ $serviceName = $this->params['serviceName'];
+ }
+
+ $this->objectStoreService = $this->client->objectStoreService($serviceName, $this->params['region']);
+
+ try {
+ $this->container = $this->objectStoreService->getContainer($this->params['container']);
+ } catch (ClientErrorResponseException $ex) {
+ // if the container does not exist and autocreate is true try to create the container on the fly
+ if (isset($this->params['autocreate']) && $this->params['autocreate'] === true) {
+ $this->container = $this->objectStoreService->createContainer($this->params['container']);
+ } else {
+ throw $ex;
+ }
+ }
+ }
+
+ /**
+ * @return string the container name where objects are stored
+ */
+ public function getStorageId() {
+ return $this->params['container'];
+ }
+
+ /**
+ * @param string $urn the unified resource name used to identify the object
+ * @param resource $stream stream with the data to write
+ * @throws Exception from openstack lib when something goes wrong
+ */
+ public function writeObject($urn, $stream) {
+ $this->init();
+ $this->container->uploadObject($urn, $stream);
+ }
+
+ /**
+ * @param string $urn the unified resource name used to identify the object
+ * @return resource stream with the read data
+ * @throws Exception from openstack lib when something goes wrong
+ */
+ public function readObject($urn) {
+ $this->init();
+ $object = $this->container->getObject($urn);
+
+ // we need to keep a reference to objectContent or
+ // the stream will be closed before we can do anything with it
+ /** @var $objectContent \Guzzle\Http\EntityBody * */
+ $objectContent = $object->getContent();
+ $objectContent->rewind();
+
+ // directly returning the object stream does not work because the GC seems to collect it, so we need a copy
+ $tmpStream = fopen('php://temp', 'r+');
+ stream_copy_to_stream($objectContent->getStream(), $tmpStream);
+ rewind($tmpStream);
+
+ return $tmpStream;
+ }
+
+ /**
+ * @param string $urn Unified Resource Name
+ * @return void
+ * @throws Exception from openstack lib when something goes wrong
+ */
+ public function deleteObject($urn) {
+ $this->init();
+ // see https://github.com/rackspace/php-opencloud/issues/243#issuecomment-30032242
+ $this->container->dataObject()->setName($urn)->delete();
+ }
+
+ public function deleteContainer($recursive = false) {
+ $this->init();
+ $this->container->delete($recursive);
+ }
+
+}
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index ecc75298b66..9657b511f15 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -279,6 +279,11 @@ abstract class Common implements \OC\Files\Storage\Storage {
/**
* check if a file or folder has been updated since $time
*
+ * The method is only used to check if the cache needs to be updated. Storage backends that don't support checking
+ * the mtime should always return false here. As a result storage implementations that always return false expect
+ * exclusive access to the backend and will not pick up files that have been added in a way that circumvents
+ * ownClouds filesystem.
+ *
* @param string $path
* @param int $time
* @return bool
diff --git a/lib/private/util.php b/lib/private/util.php
index 94005daef61..225cd64dbb3 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -12,6 +12,45 @@ class OC_Util {
private static $rootMounted=false;
private static $fsSetup=false;
+ private static function initLocalStorageRootFS() {
+ // mount local file backend as root
+ $configDataDirectory = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
+ //first set up the local "root" storage
+ \OC\Files\Filesystem::initMounts();
+ if(!self::$rootMounted) {
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir'=>$configDataDirectory), '/');
+ self::$rootMounted = true;
+ }
+ }
+
+ /**
+ * mounting an object storage as the root fs will in essence remove the
+ * necessity of a data folder being present.
+ * TODO make home storage aware of this and use the object storage instead of local disk access
+ * @param array $config containing 'class' and optional 'arguments'
+ */
+ private static function initObjectStoreRootFS($config) {
+ // check misconfiguration
+ if (empty($config['class'])) {
+ \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
+ }
+ if (!isset($config['arguments'])) {
+ $config['arguments'] = array();
+ }
+
+ // instantiate object store implementation
+ $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
+ // mount with plain / root object store implementation
+ $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage';
+
+ // mount object storage as root
+ \OC\Files\Filesystem::initMounts();
+ if(!self::$rootMounted) {
+ \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/');
+ self::$rootMounted = true;
+ }
+ }
+
/**
* Can be set up
* @param string $user
@@ -39,12 +78,12 @@ class OC_Util {
self::$fsSetup=true;
}
- $configDataDirectory = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
- //first set up the local "root" storage
- \OC\Files\Filesystem::initMounts();
- if(!self::$rootMounted) {
- \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir'=>$configDataDirectory), '/');
- self::$rootMounted = true;
+ //check if we are using an object storage
+ $objectStore = OC_Config::getValue( 'objectstore' );
+ if ( isset( $objectStore ) ) {
+ self::initObjectStoreRootFS($objectStore);
+ } else {
+ self::initLocalStorageRootFS();
}
if ($user != '' && !OCP\User::userExists($user)) {
@@ -60,24 +99,33 @@ class OC_Util {
/**
* @var \OC\Files\Storage\Storage $storage
*/
- if ($storage->instanceOfStorage('\OC\Files\Storage\Home')) {
- $user = $storage->getUser()->getUID();
- $quota = OC_Util::getUserQuota($user);
- if ($quota !== \OC\Files\SPACE_UNLIMITED) {
- return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
+ if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
+ || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
+ ) {
+ if (is_object($storage->getUser())) {
+ $user = $storage->getUser()->getUID();
+ $quota = OC_Util::getUserQuota($user);
+ if ($quota !== \OC\Files\SPACE_UNLIMITED) {
+ return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
+ }
}
}
return $storage;
});
- $userDir = '/'.$user.'/files';
- $userRoot = OC_User::getHome($user);
- $userDirectory = $userRoot . '/files';
- if( !is_dir( $userDirectory )) {
- mkdir( $userDirectory, 0755, true );
- OC_Util::copySkeleton($userDirectory);
+ // copy skeleton for local storage only
+ if ( ! isset( $objectStore ) ) {
+ $userRoot = OC_User::getHome($user);
+ $userDirectory = $userRoot . '/files';
+ if( !is_dir( $userDirectory )) {
+ mkdir( $userDirectory, 0755, true );
+ OC_Util::copySkeleton($userDirectory);
+ }
}
+
+ $userDir = '/'.$user.'/files';
+
//jail the user into his "home" directory
\OC\Files\Filesystem::init($user, $userDir);
diff --git a/lib/public/files/objectstore/iobjectstore.php b/lib/public/files/objectstore/iobjectstore.php
new file mode 100644
index 00000000000..b2c5a9da134
--- /dev/null
+++ b/lib/public/files/objectstore/iobjectstore.php
@@ -0,0 +1,33 @@
+<?php
+
+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
+ * @return resource stream with the read data
+ * @throws Exception when something goes wrong, message will be logged
+ */
+ function readObject($urn);
+
+ /**
+ * @param string $urn the unified resource name used to identify the object
+ * @param resource $stream stream with the data to write
+ * @throws Exception when something goes wrong, message will be logged
+ */
+ function writeObject($urn, $stream);
+
+ /**
+ * @param string $urn the unified resource name used to identify the object
+ * @return void
+ * @throws Exception when something goes wrong, message will be logged
+ */
+ function deleteObject($urn);
+
+} \ No newline at end of file