[Pkg-owncloud-commits] [owncloud] 33/273: Only initialize the swift container when manipulating an object
David Prévot
taffit at moszumanska.debian.org
Fri Jul 4 03:12:55 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 eb97eee964b97613a3fab7c101688e6515f393b1
Author: Robin Appelman <icewind at owncloud.com>
Date: Tue Jun 24 14:42:52 2014 +0200
Only initialize the swift container when manipulating an object
---
lib/private/files/objectstore/swift.php | 44 ++++++++++++++++++++++++---------
1 file changed, 32 insertions(+), 12 deletions(-)
diff --git a/lib/private/files/objectstore/swift.php b/lib/private/files/objectstore/swift.php
index be12d45..8957c8f 100644
--- a/lib/private/files/objectstore/swift.php
+++ b/lib/private/files/objectstore/swift.php
@@ -26,6 +26,15 @@ use OpenCloud\OpenStack;
use OpenCloud\Rackspace;
class Swift implements IObjectStore {
+ /**
+ * @var \OpenCloud\OpenStack
+ */
+ private $client;
+
+ /**
+ * @var array
+ */
+ private $params;
/**
* @var \OpenCloud\ObjectStore\Service
@@ -46,26 +55,33 @@ class Swift implements IObjectStore {
$params['autocreate'] = false;
}
- // the OpenCloud client library will default to 'cloudFiles' if $serviceName is null
- $serviceName = null;
- if ($params['serviceName']) {
- $serviceName = $params['serviceName'];
- }
-
if (isset($params['apiKey'])) {
- $client = new Rackspace($params['url'], $params);
+ $this->client = new Rackspace($params['url'], $params);
} else {
- $client = new OpenStack($params['url'], $params);
+ $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 = $client->objectStoreService($serviceName, $params['region']);
+ $this->objectStoreService = $this->client->objectStoreService($serviceName, $this->params['region']);
try {
- $this->container = $this->objectStoreService->getContainer($params['container']);
+ $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($params['autocreate']) && $params['autocreate'] === true) {
- $this->container = $this->objectStoreService->createContainer($params['container']);
+ $this->container = $this->objectStoreService->createContainer($this->params['container']);
} else {
throw $ex;
}
@@ -76,7 +92,7 @@ class Swift implements IObjectStore {
* @return string the container name where objects are stored
*/
public function getStorageId() {
- return $this->container->name;
+ return $this->params['container'];
}
/**
@@ -85,6 +101,7 @@ class Swift implements IObjectStore {
* @throws Exception from openstack lib when something goes wrong
*/
public function writeObject($urn, $stream) {
+ $this->init();
$this->container->uploadObject($urn, $stream);
}
@@ -94,6 +111,7 @@ class Swift implements IObjectStore {
* @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
@@ -116,11 +134,13 @@ class Swift implements IObjectStore {
* @throws Exception from openstack lib when something goes wrong
*/
public function deleteObject($urn) {
+ $this->init();
$object = $this->container->getObject($urn);
$object->delete();
}
public function deleteContainer($recursive = false) {
+ $this->init();
$this->container->delete($recursive);
}
--
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