summaryrefslogtreecommitdiffstats
path: root/lib/private/files
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2014-06-13 17:22:21 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2014-06-18 12:53:20 +0200
commit5722e31d1a277199e9b8ae85a21685abf3436418 (patch)
treeb06e4bc30229a1d2f519190b782403a5871b9ca6 /lib/private/files
parent1410cb10b4cb31a52901ee12e38a2c27d2177cf3 (diff)
downloadnextcloud-server-5722e31d1a277199e9b8ae85a21685abf3436418.tar.gz
nextcloud-server-5722e31d1a277199e9b8ae85a21685abf3436418.zip
add autocreate config option for containers, implement autocreate and delete of containers, use generated container names for tests
Diffstat (limited to 'lib/private/files')
-rw-r--r--lib/private/files/objectstore/swift.php32
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/private/files/objectstore/swift.php b/lib/private/files/objectstore/swift.php
index b4ef8996cb8..53367367af0 100644
--- a/lib/private/files/objectstore/swift.php
+++ b/lib/private/files/objectstore/swift.php
@@ -20,10 +20,15 @@
namespace OC\Files\ObjectStore;
+use Guzzle\Http\Exception\ClientErrorResponseException;
use OpenCloud\OpenStack;
class Swift extends AbstractObjectStore {
+ /**
+ * @var \OpenCloud\ObjectStore\Service
+ */
+ private $objectStoreService;
/**
* @var \OpenCloud\ObjectStore\Resource\Container
@@ -34,6 +39,13 @@ class Swift extends AbstractObjectStore {
if (!isset($params['username']) || !isset($params['password']) ) {
throw new \Exception("Access Key and Secret have to be configured.");
}
+ if (!isset($params['container'])) {
+ $params['container'] = 'owncloud';
+ }
+ if (!isset($params['autocreate'])) {
+ // should only be true for tests
+ $params['autocreate'] = false;
+ }
$secret = array(
'username' => $params['username'],
@@ -54,10 +66,18 @@ class Swift extends AbstractObjectStore {
$client = new OpenStack($params['url'], $secret);
- /** @var $objectStoreService \OpenCloud\ObjectStore\Service **/
- $objectStoreService = $client->objectStoreService($serviceName, $params['region']);
-
- $this->container = $objectStoreService->getContainer($params['container']);
+ $this->objectStoreService = $client->objectStoreService($serviceName, $params['region']);
+
+ try {
+ $this->container = $this->objectStoreService->getContainer($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($params['autocreate']) && $params['autocreate'] === true) {
+ $this->container = $this->objectStoreService->createContainer($params['container']);
+ } else {
+ throw $ex;
+ }
+ }
//set the user via parent constructor, also initializes the root of the filecache
parent::__construct($params);
@@ -105,4 +125,8 @@ class Swift extends AbstractObjectStore {
$this->container->uploadObject($urn, $fileData);
}
+ public function deleteContainer($recursive = false) {
+ $this->container->delete($recursive);
+ }
+
}