Edward Chernenko has uploaded a new change for review.
https://gerrit.wikimedia.org/r/250145
Change subject: [bug] Fix incorrect directory listing in AmazonS3FileIterator.
......................................................................
[bug] Fix incorrect directory listing in AmazonS3FileIterator.
Symptom: it was noticed that AmazonS3FileBackend doesn't delete thumbnails
when the original image is deleted.
===============================================================================
Investigation showed two bugs in AmazonS3FileIterator:
1) First, when we want to get a list of objects starting with some prefix,
requested prefix MUST end with a slash (otherwise S3 will return
a "prefix suggestion" instead of the list itself).
If we (incorrectly) ask for "dir", S3 answers "dir/",
if we (correctly) ask for "dir/", S3 answers "dir/file1", "dir/file2", etc.
2) Prefix (pseudo-directory name) wasn't filtered from returned filenames.
(listing of "dir/" returned "dir/file1" instead of "file1")
===============================================================================
This fix addresses both issues.
After it is applied, thumbnails are deleted OK when image is deleted.
Regression testing performed: uploads, reuploads, reverts, deleting one version
of the file, deleting entire file, undeleting file. No impact detected.
Change-Id: I7fa9e52267b9ee506add6708f903e135e404de75
---
M s3/AmazonS3FileBackend.php
1 file changed, 14 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AWS
refs/changes/45/250145/1
diff --git a/s3/AmazonS3FileBackend.php b/s3/AmazonS3FileBackend.php
index b160376..86fe3c8 100644
--- a/s3/AmazonS3FileBackend.php
+++ b/s3/AmazonS3FileBackend.php
@@ -436,7 +436,7 @@
$res = $this->client->putObjectAcl(
array(
'ACL' => CannedAcl::PUBLIC_READ,
'Bucket' => $container,
- 'Key' => $key
+ 'Key' => "$dir/$key"
) );
} catch ( S3Exception $e ) {
$this->handleException( $e, $status,
__METHOD__, $params );
@@ -467,7 +467,7 @@
$res = $this->client->putObjectAcl(
array(
'ACL' =>
CannedAcl::PRIVATE_ACCESS,
'Bucket' => $container,
- 'Key' => $key
+ 'Key' => "$dir/$key"
) );
} catch ( S3Exception $e ) {
$this->handleException( $e, $status,
__METHOD__, $params );
@@ -522,7 +522,18 @@
private $client, $container, $dir, $topOnly, $limit;
private $index, $results, $marker, $finished;
+ private $suffixStart;
+
public function __construct( S3Client $client, $container, $dir, array
$params, $limit = 500 ) {
+ /* "Directory" must end with the slash,
+ otherwise S3 will return PRE (prefix) suggestion
+ instead of the listing itself */
+ if(substr($dir, -1, 1) != '/') {
+ $dir .= '/';
+ }
+
+ $this->suffixStart = strlen($dir); // size of "path/to/dir/"
+
$this->client = $client;
$this->container = $container;
$this->dir = $dir;
@@ -539,7 +550,7 @@
public function current() {
$this->init();
- return $this->results['Contents'][$this->index]['Key'];
+ return substr( $this->results['Contents'][$this->index]['Key'],
$this->suffixStart );
}
public function next() {
--
To view, visit https://gerrit.wikimedia.org/r/250145
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7fa9e52267b9ee506add6708f903e135e404de75
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AWS
Gerrit-Branch: master
Gerrit-Owner: Edward Chernenko <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits