summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2014-10-06 11:08:21 +0200
committerVincent Petry <pvince81@owncloud.com>2014-10-08 18:50:02 +0200
commitf664a31deca2b4c0034b93a439456307aedd23d7 (patch)
treebed1037ad07dc1685df4e494e1a7d1e91dc9a530 /apps/files_external/lib
parent0d0c9d0bb35195cc5b40a189523599df56d8368e (diff)
downloadnextcloud-server-f664a31deca2b4c0034b93a439456307aedd23d7.tar.gz
nextcloud-server-f664a31deca2b4c0034b93a439456307aedd23d7.zip
extract batchDelete(), better comments
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r--apps/files_external/lib/amazons3.php62
1 files changed, 31 insertions, 31 deletions
diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php
index 8e893b0aac6..808de16c8a8 100644
--- a/apps/files_external/lib/amazons3.php
+++ b/apps/files_external/lib/amazons3.php
@@ -72,6 +72,9 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return $path;
}
+ /**
+ * when running the tests wait to let the buckets catch up
+ */
private function testTimeout() {
if ($this->test) {
sleep($this->timeout);
@@ -208,51 +211,48 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return false;
}
+ return $this->batchDelete($path);
+ }
+
+ protected function clearBucket() {
try {
- do { // batches of 1000
- // Since there are no real directories on S3, we need
- // to delete all objects prefixed with the path.
- $objects = $this->connection->listObjects(array(
- 'Bucket' => $this->bucket,
- 'Prefix' => $path . '/'
- ));
+ $this->connection->clearBucket($this->bucket);
+ return true;
+ // clearBucket() is not working with Ceph, so if it fails we try the slower approach
+ } catch (\Exception $e) {
+ return $this->batchDelete();
+ }
+ return false;
+ }
+
+ private function batchDelete ($path = null) {
+ $params = array(
+ 'Bucket' => $this->bucket
+ );
+ if ($path !== null) {
+ $params['Prefix'] = $path . '/';
+ }
+ try {
+ // Since there are no real directories on S3, we need
+ // to delete all objects prefixed with the path.
+ do {
+ // instead of the iterator, manually loop over the list ...
+ $objects = $this->connection->listObjects($params);
+ // ... so we can delete the files in batches
$this->connection->deleteObjects(array(
'Bucket' => $this->bucket,
'Objects' => $objects['Contents']
));
$this->testTimeout();
+ // we reached the end when the list is no longer truncated
} while ($objects['IsTruncated']);
} catch (S3Exception $e) {
\OCP\Util::logException('files_external', $e);
return false;
}
-
return true;
}
- protected function clearBucket() {
- try {
- $this->connection->clearBucket($this->bucket);
- // clearBucket() is not working with Ceph, so if it fails we try the slower approach
- } catch (\Exception $e) {
- try {
- do { // batches of 1000
- $objects = $this->connection->listObjects(array(
- 'Bucket' => $this->bucket
- ));
- $this->connection->deleteObjects(array(
- 'Bucket' => $this->bucket,
- 'Objects' => $objects['Contents'] // delete 1000 objects in one http call
- ));
- $this->testTimeout();
- } while ($objects['IsTruncated']);
- } catch (S3Exception $e) {
- \OCP\Util::logException('files_external', $e);
- return false;
- }
- }
- }
-
public function opendir($path) {
$path = $this->normalizePath($path);