summaryrefslogtreecommitdiffstats
path: root/lib/private/files/objectstore/swift.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/files/objectstore/swift.php')
-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);
+ }
+
}