summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-09-08 18:19:59 +0200
committerLukas Reschke <lukas@owncloud.com>2014-09-08 18:19:59 +0200
commit0ec9c2ccf8a2fd3451135c65146ff2c04ef0457b (patch)
treec10c653bf2b434baeb74460aaf8a0c23f0202f1b /apps/files_external
parentc79c894dbb6bda06ff32db4418b8fe6af5b27d4a (diff)
parenta1f4a0601bba05920d1f62f683a085daed65dde3 (diff)
downloadnextcloud-server-0ec9c2ccf8a2fd3451135c65146ff2c04ef0457b.tar.gz
nextcloud-server-0ec9c2ccf8a2fd3451135c65146ff2c04ef0457b.zip
Merge pull request #10885 from owncloud/swift-hasupdated
Fix hasUpdated for folders in openstack swift
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/appinfo/app.php4
-rw-r--r--apps/files_external/lib/swift.php68
2 files changed, 52 insertions, 20 deletions
diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php
index 50a73bd5f9a..3486b8db51b 100644
--- a/apps/files_external/appinfo/app.php
+++ b/apps/files_external/appinfo/app.php
@@ -111,9 +111,9 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\Swift', array(
'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'),
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php
index 47ab3294673..1c56d180e2f 100644
--- a/apps/files_external/lib/swift.php
+++ b/apps/files_external/lib/swift.php
@@ -26,6 +26,7 @@ use Guzzle\Http\Exception\ClientErrorResponseException;
use OpenCloud;
use OpenCloud\Common\Exceptions;
use OpenCloud\OpenStack;
+use OpenCloud\Rackspace;
use OpenCloud\ObjectStore\Resource\DataObject;
use OpenCloud\ObjectStore\Exception;
@@ -67,15 +68,16 @@ class Swift extends \OC\Files\Storage\Common {
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);
}
@@ -93,20 +95,21 @@ class Swift extends \OC\Files\Storage\Common {
}
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';
}
@@ -114,21 +117,25 @@ class Swift extends \OC\Files\Storage\Common {
'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']);
@@ -150,7 +157,7 @@ class Swift extends \OC\Files\Storage\Common {
return false;
}
- if($path !== '.') {
+ if ($path !== '.') {
$path .= '/';
}
@@ -236,7 +243,7 @@ class Swift extends \OC\Files\Storage\Common {
\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;
}
@@ -246,11 +253,14 @@ class Swift extends \OC\Files\Storage\Common {
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);
@@ -274,7 +284,7 @@ class Swift extends \OC\Files\Storage\Common {
}
$stat = array();
- $stat['size'] = (int) $object->getContentLength();
+ $stat['size'] = (int)$object->getContentLength();
$stat['mtime'] = $mtime;
$stat['atime'] = time();
return $stat;
@@ -416,7 +426,7 @@ class Swift extends \OC\Files\Storage\Common {
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;
@@ -429,7 +439,7 @@ class Swift extends \OC\Files\Storage\Common {
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;
@@ -499,6 +509,28 @@ class Swift extends \OC\Files\Storage\Common {
unlink($tmpFile);
}
+ public function hasUpdated($path, $time) {
+ if ($this->is_file($path)) {
+ return parent::hasUpdated($path, $time);
+ }
+ $path = $this->normalizePath($path);
+ $dh = $this->opendir($path);
+ $content = array();
+ while (($file = readdir($dh)) !== false) {
+ $content[] = $file;
+ }
+ if ($path === '.') {
+ $path = '';
+ }
+ $cachedContent = $this->getCache()->getFolderContents($path);
+ $cachedNames = array_map(function ($content) {
+ return $content['name'];
+ }, $cachedContent);
+ sort($cachedNames);
+ sort($content);
+ return $cachedNames != $content;
+ }
+
/**
* check if curl is installed
*/