Skip to content

Commit

Permalink
[FEATURE] Load nested directories without existing S3 object
Browse files Browse the repository at this point in the history
resolves #45, resolves #67
  • Loading branch information
Lagerregal committed Mar 3, 2021
1 parent 4d27f45 commit 1671cea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Classes/Driver/AmazonS3Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function folderExists($identifier)
if (substr($identifier, -1) !== '/') {
$identifier .= '/';
}
return $this->objectExists($identifier);
return $this->prefixExists($identifier);
}

/**
Expand All @@ -344,7 +344,7 @@ public function fileExistsInFolder($fileName, $folderIdentifier)
*/
public function folderExistsInFolder($folderName, $folderIdentifier)
{
return $this->objectExists($folderIdentifier . $folderName . '/');
return $this->prefixExists($folderIdentifier . $folderName . '/');
}

/**
Expand Down Expand Up @@ -1179,11 +1179,27 @@ protected function getMessageQueue()
* @param string $identifier
* @return bool
*/
protected function objectExists($identifier)
protected function objectExists(string $identifier): bool
{
return $this->getMetaInfo($identifier) !== null;
}

/**
* Checks if an prefix exists.
* This is necessary because a folder is not an object for S3.
*
* @param string $identifier
* @return bool
*/
protected function prefixExists(string $identifier): bool
{
if ($this->objectExists($identifier)) {
return true;
}
$objects = $this->getListObjects($identifier, ['MaxKeys' => 1]);
return count($objects) > 0;
}

/**
* Get the meta information of an file or folder
*
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"license": "LGPL-3.0-or-later",
"require": {
"php": ">=7.2",
"typo3/cms-core": "^9.5.0 || ^10.4.10",
"aws/aws-sdk-php": "^3.136"
},
Expand Down

0 comments on commit 1671cea

Please sign in to comment.