Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
f664a31d
Commit
f664a31d
authored
10 years ago
by
Jörn Friedrich Dreyer
Committed by
Vincent Petry
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
extract batchDelete(), better comments
parent
0d0c9d0b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/files_external/lib/amazons3.php
+31
-31
31 additions, 31 deletions
apps/files_external/lib/amazons3.php
with
31 additions
and
31 deletions
apps/files_external/lib/amazons3.php
+
31
−
31
View file @
f664a31d
...
@@ -72,6 +72,9 @@ class AmazonS3 extends \OC\Files\Storage\Common {
...
@@ -72,6 +72,9 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return
$path
;
return
$path
;
}
}
/**
* when running the tests wait to let the buckets catch up
*/
private
function
testTimeout
()
{
private
function
testTimeout
()
{
if
(
$this
->
test
)
{
if
(
$this
->
test
)
{
sleep
(
$this
->
timeout
);
sleep
(
$this
->
timeout
);
...
@@ -208,49 +211,46 @@ class AmazonS3 extends \OC\Files\Storage\Common {
...
@@ -208,49 +211,46 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return
false
;
return
false
;
}
}
try
{
return
$this
->
batchDelete
(
$path
);
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
->
deleteObjects
(
array
(
'Bucket'
=>
$this
->
bucket
,
'Objects'
=>
$objects
[
'Contents'
]
));
$this
->
testTimeout
();
}
while
(
$objects
[
'IsTruncated'
]);
}
catch
(
S3Exception
$e
)
{
\OCP\Util
::
logException
(
'files_external'
,
$e
);
return
false
;
}
return
true
;
}
}
protected
function
clearBucket
()
{
protected
function
clearBucket
()
{
try
{
try
{
$this
->
connection
->
clearBucket
(
$this
->
bucket
);
$this
->
connection
->
clearBucket
(
$this
->
bucket
);
return
true
;
// clearBucket() is not working with Ceph, so if it fails we try the slower approach
// clearBucket() is not working with Ceph, so if it fails we try the slower approach
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
try
{
return
$this
->
batchDelete
();
do
{
// batches of 1000
}
$objects
=
$this
->
connection
->
listObjects
(
array
(
return
false
;
}
private
function
batchDelete
(
$path
=
null
)
{
$params
=
array
(
'Bucket'
=>
$this
->
bucket
'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
(
$this
->
connection
->
deleteObjects
(
array
(
'Bucket'
=>
$this
->
bucket
,
'Bucket'
=>
$this
->
bucket
,
'Objects'
=>
$objects
[
'Contents'
]
// delete 1000 objects in one http call
'Objects'
=>
$objects
[
'Contents'
]
));
));
$this
->
testTimeout
();
$this
->
testTimeout
();
// we reached the end when the list is no longer truncated
}
while
(
$objects
[
'IsTruncated'
]);
}
while
(
$objects
[
'IsTruncated'
]);
}
catch
(
S3Exception
$e
)
{
}
catch
(
S3Exception
$e
)
{
\OCP\Util
::
logException
(
'files_external'
,
$e
);
\OCP\Util
::
logException
(
'files_external'
,
$e
);
return
false
;
return
false
;
}
}
}
return
true
;
}
}
public
function
opendir
(
$path
)
{
public
function
opendir
(
$path
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment