Skip to content

Commit

Permalink
Merge pull request #45 from flownative/bugfix/unique-temporary-filenames
Browse files Browse the repository at this point in the history
BUGFIX: Temporary filename might not be unique
  • Loading branch information
kdambekalns authored Aug 4, 2021
2 parents 68188f7 + 7b20ef9 commit ab97471
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Classes/S3Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Neos\Flow\ResourceManagement\Storage\Exception;
use Neos\Flow\ResourceManagement\Storage\StorageObject;
use Neos\Flow\ResourceManagement\Storage\WritableStorageInterface;
use Neos\Flow\Utility\Algorithms;
use Neos\Flow\Utility\Environment;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -164,7 +165,7 @@ public function getKeyPrefix()
*/
public function importResource($source, $collectionName)
{
$temporaryTargetPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('Flownative_Aws_S3_');
$temporaryTargetPathAndFilename = $this->environment->getPathToTemporaryDirectory() . 'Flownative_Aws_S3_' . Algorithms::generateRandomToken(12) . '.tmp';

if (is_resource($source)) {
try {
Expand Down Expand Up @@ -246,7 +247,7 @@ public function importUploadedResource(array $uploadInfo, $collectionName)
throw new Exception(sprintf('The temporary file "%s" of the file upload does not exist (anymore).', $sourcePathAndFilename), 1428909075);
}

$newSourcePathAndFilename = $this->environment->getPathToTemporaryDirectory() . 'Flownative_Aws_S3_' . uniqid() . '.tmp';
$newSourcePathAndFilename = $this->environment->getPathToTemporaryDirectory() . 'Flownative_Aws_S3_' . Algorithms::generateRandomToken(12) . '.tmp';
if (move_uploaded_file($sourcePathAndFilename, $newSourcePathAndFilename) === false) {
throw new Exception(sprintf('The uploaded file "%s" could not be moved to the temporary location "%s".', $sourcePathAndFilename, $newSourcePathAndFilename), 1428909076);
}
Expand Down

0 comments on commit ab97471

Please sign in to comment.