Skip to content

Commit

Permalink
BUGFIX: Prevent copying same file multiple times
Browse files Browse the repository at this point in the history
When a file exists multiple times as variant it was copied n-1 times
because the first time it was matched against the known objects
the known object info was deleted. Further checks then initiated 
the copy process again.
  • Loading branch information
Sebobo authored Jun 30, 2020
1 parent 76daf3f commit cf8495a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Classes/S3Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function publishCollection(CollectionInterface $collection, callable $cal
$objectName = $this->keyPrefix . $this->getRelativePublicationPathAndFilename($object);
if (array_key_exists($objectName, $potentiallyObsoleteObjects)) {
$this->systemLogger->debug(sprintf('The resource object "%s" (MD5: %s) has already been published to bucket "%s", no need to re-publish', $objectName, $object->getMd5() ?: 'unknown', $this->bucketName));
unset($potentiallyObsoleteObjects[$objectName]);
$potentiallyObsoleteObjects[$objectName] = false;
} else {
$options = array(
'ACL' => 'public-read',
Expand All @@ -230,11 +230,14 @@ public function publishCollection(CollectionInterface $collection, callable $cal
/** @var \Neos\Flow\ResourceManagement\Storage\StorageObject $object */
$this->publishFile($object->getStream(), $this->getRelativePublicationPathAndFilename($object), $object);
$objectName = $this->keyPrefix . $this->getRelativePublicationPathAndFilename($object);
unset($potentiallyObsoleteObjects[$objectName]);
$potentiallyObsoleteObjects[$objectName] = false;
}
}

foreach (array_keys($potentiallyObsoleteObjects) as $relativePathAndFilename) {
if (!$potentiallyObsoleteObjects[$relativePathAndFilename]) {
continue;
}
$this->systemLogger->debug(sprintf('Deleted obsolete resource "%s" from bucket "%s"', $relativePathAndFilename, $this->bucketName));
$this->s3Client->deleteObject(array(
'Bucket' => $this->bucketName,
Expand Down

0 comments on commit cf8495a

Please sign in to comment.