mirror of
https://github.com/nextcloud/server.git
synced 2024-08-19 02:10:47 +02:00
Merge pull request #8100 from nextcloud/s3-folder-delete
Fix deleting folders when using s3 external storage
This commit is contained in:
commit
12c9bad5b2
@ -101,7 +101,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
|||||||
$keys = array_keys($this->objectCache->getData());
|
$keys = array_keys($this->objectCache->getData());
|
||||||
$keyLength = strlen($key);
|
$keyLength = strlen($key);
|
||||||
foreach ($keys as $existingKey) {
|
foreach ($keys as $existingKey) {
|
||||||
if (substr($existingKey, 0, $keyLength) === $keys) {
|
if (substr($existingKey, 0, $keyLength) === $key) {
|
||||||
unset($this->objectCache[$existingKey]);
|
unset($this->objectCache[$existingKey]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,17 +242,22 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
|||||||
$params['Prefix'] = $path . '/';
|
$params['Prefix'] = $path . '/';
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
$connection = $this->getConnection();
|
||||||
// Since there are no real directories on S3, we need
|
// Since there are no real directories on S3, we need
|
||||||
// to delete all objects prefixed with the path.
|
// to delete all objects prefixed with the path.
|
||||||
do {
|
do {
|
||||||
// instead of the iterator, manually loop over the list ...
|
// instead of the iterator, manually loop over the list ...
|
||||||
$objects = $this->getConnection()->listObjects($params);
|
$objects = $connection->listObjects($params);
|
||||||
// ... so we can delete the files in batches
|
// ... so we can delete the files in batches
|
||||||
$this->getConnection()->deleteObjects(array(
|
if (isset($objects['Contents'])) {
|
||||||
'Bucket' => $this->bucket,
|
$connection->deleteObjects([
|
||||||
'Objects' => $objects['Contents']
|
'Bucket' => $this->bucket,
|
||||||
));
|
'Delete' => [
|
||||||
$this->testTimeout();
|
'Objects' => $objects['Contents']
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
$this->testTimeout();
|
||||||
|
}
|
||||||
// we reached the end when the list is no longer truncated
|
// we reached the end when the list is no longer truncated
|
||||||
} while ($objects['IsTruncated']);
|
} while ($objects['IsTruncated']);
|
||||||
} catch (S3Exception $e) {
|
} catch (S3Exception $e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user