Skip to content

Commit

Permalink
DP-488 Fix S3 service not being able to see folders
Browse files Browse the repository at this point in the history
  • Loading branch information
tomonorman committed Mar 30, 2022
1 parent 1497ad1 commit f956ece
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Components/S3FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ public function blobExists($container = '', $name = '')
try {
$this->checkConnection();

// If the name ends in a / we know DF is looking for a "folder". S3 does not really have the concept
// of folders per se so we need to check for the prefix.
if (substr($name, -1) === '/') {
$options = array(
"Bucket" => $container,
"Prefix" => $name,
// We only need to get one to prove the folder exists
"MaxKeys" => 1
);

$list = $this->blobConn->listObjectsV2($options);
// if there is a "Contents" Array within our list, we know that there is a folder of that name
return $list['Contents'] ? true : false;
}

// Just search for the file itself.
return $this->blobConn->doesObjectExist($container, $name);
} catch (\Exception $ex) {
return false;
Expand Down

0 comments on commit f956ece

Please sign in to comment.