'user' => (string)$l->t('Username'),
'bucket' => (string)$l->t('Bucket'),
'region' => '&'.$l->t('Region (optional for OpenStack Object Storage)'),
- 'key' => '*'.$l->t('API Key (required for Rackspace Cloud Files)'),
+ 'key' => '&*'.$l->t('API Key (required for Rackspace Cloud Files)'),
'tenant' => '&'.$l->t('Tenantname (required for OpenStack Object Storage)'),
- 'password' => '*'.$l->t('Password (required for OpenStack Object Storage)'),
+ 'password' => '&*'.$l->t('Password (required for OpenStack Object Storage)'),
'service_name' => '&'.$l->t('Service Name (required for OpenStack Object Storage)'),
'url' => '&'.$l->t('URL of identity endpoint (required for OpenStack Object Storage)'),
'timeout' => '&'.$l->t('Timeout of HTTP requests in seconds'),
use OpenCloud;
use OpenCloud\Common\Exceptions;
use OpenCloud\OpenStack;
+use OpenCloud\Rackspace;
use OpenCloud\ObjectStore\Resource\DataObject;
use OpenCloud\ObjectStore\Exception;
return $path;
}
- const SUBCONTAINER_FILE='.subcontainers';
+ const SUBCONTAINER_FILE = '.subcontainers';
/**
* translate directory path to container name
+ *
* @param string $path
* @return string
*/
private function getContainerName($path) {
- $path=trim(trim($this->root, '/') . "/".$path, '/.');
+ $path = trim(trim($this->root, '/') . "/" . $path, '/.');
return str_replace('/', '\\', $path);
}
}
public function __construct($params) {
- if ((!isset($params['key']) and !isset($params['password']))
- or !isset($params['user']) or !isset($params['bucket'])
- or !isset($params['region'])) {
+ if ((empty($params['key']) and empty($params['password']))
+ or empty($params['user']) or empty($params['bucket'])
+ or empty($params['region'])
+ ) {
throw new \Exception("API Key or password, Username, Bucket and Region have to be configured.");
}
$this->id = 'swift::' . $params['user'] . md5($params['bucket']);
$this->bucket = $params['bucket'];
- if (!isset($params['url'])) {
+ if (empty($params['url'])) {
$params['url'] = 'https://identity.api.rackspacecloud.com/v2.0/';
}
- if (!isset($params['service_name'])) {
+ if (empty($params['service_name'])) {
$params['service_name'] = 'cloudFiles';
}
'username' => $params['user'],
);
- if (isset($params['password'])) {
+ if (!empty($params['password'])) {
$settings['password'] = $params['password'];
- } else if (isset($params['key'])) {
+ } else if (!empty($params['key'])) {
$settings['apiKey'] = $params['key'];
}
- if (isset($params['tenant'])) {
+ if (!empty($params['tenant'])) {
$settings['tenantName'] = $params['tenant'];
}
- if (isset($params['timeout'])) {
+ if (!empty($params['timeout'])) {
$settings['timeout'] = $params['timeout'];
}
- $this->anchor = new OpenStack($params['url'], $settings);
+ if (isset($settings['apiKey'])) {
+ $this->anchor = new Rackspace($params['url'], $settings);
+ } else {
+ $this->anchor = new OpenStack($params['url'], $settings);
+ }
$this->connection = $this->anchor->objectStoreService($params['service_name'], $params['region']);
return false;
}
- if($path !== '.') {
+ if ($path !== '.') {
$path .= '/';
}
\OC\Files\Stream\Dir::register('swift' . $path, $files);
return opendir('fakedir://swift' . $path);
- } catch (Exception $e) {
+ } catch (\Exception $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
return false;
}
public function stat($path) {
$path = $this->normalizePath($path);
- if ($this->is_dir($path) && $path != '.') {
+ if ($path === '.') {
+ $path = '';
+ } else if ($this->is_dir($path)) {
$path .= '/';
}
try {
+ /** @var DataObject $object */
$object = $this->container->getPartialObject($path);
} catch (ClientErrorResponseException $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
}
$stat = array();
- $stat['size'] = (int) $object->getContentLength();
+ $stat['size'] = (int)$object->getContentLength();
$stat['mtime'] = $mtime;
$stat['atime'] = time();
return $stat;
try {
$source = $this->container->getPartialObject($path1);
- $source->copy($this->bucket.'/'.$path2);
+ $source->copy($this->bucket . '/' . $path2);
} catch (ClientErrorResponseException $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
return false;
try {
$source = $this->container->getPartialObject($path1 . '/');
- $source->copy($this->bucket.'/'.$path2 . '/');
+ $source->copy($this->bucket . '/' . $path2 . '/');
} catch (ClientErrorResponseException $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
return false;