Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fogelito committed Oct 12, 2023
1 parent aa7060a commit 0bd69e1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
70 changes: 34 additions & 36 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Storage/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class Device
/**
* Sets the maximum number of keys returned to the response. By default, the action returns up to 1,000 key names.
*/
protected const MAX_KEYS = 1000;
protected const MAX_PAGE_SIZE = PHP_INT_MAX;

/**
* Set Transfer Chunk Size
Expand Down Expand Up @@ -276,11 +276,11 @@ abstract public function getPartitionTotalSpace(): float;
* Get all files and directories inside a directory.
*
* @param string $dir Directory to scan
* @param int $keys
* @param int $max
* @param string $continuationToken
* @return array<mixed>
*/
abstract public function getFiles(string $dir, int $keys = self::MAX_KEYS, string $continuationToken = ''): array;
abstract public function getFiles(string $dir, int $max = self::MAX_PAGE_SIZE, string $continuationToken = ''): array;

/**
* Get the absolute path by resolving strings like ../, .., //, /\ and so on.
Expand Down
10 changes: 5 additions & 5 deletions src/Storage/Device/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,13 @@ public function getPartitionTotalSpace(): float
return \disk_total_space($this->getRoot());
}

/**
* Get all files and directories inside a directory.
*
* @param string $dir Directory to scan
/**s
* @param string $dir
* @param int $max
* @param string $continuationToken
* @return string[]
*/
public function getFiles(string $dir, int $keys = self::MAX_KEYS, string $continuationToken = ''): array
public function getFiles(string $dir, int $max = self::MAX_PAGE_SIZE, string $continuationToken = ''): array
{
if (! (\str_ends_with($dir, DIRECTORY_SEPARATOR))) {
$dir .= DIRECTORY_SEPARATOR;
Expand Down
14 changes: 8 additions & 6 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class S3 extends Device

const ACL_AUTHENTICATED_READ = 'authenticated-read';

protected const MAX_PAGE_SIZE = 1000;

/**
* @var string
*/
Expand Down Expand Up @@ -481,10 +483,10 @@ public function delete(string $path, bool $recursive = false): bool
*
* @throws Exception
*/
private function listObjects(string $prefix = '', int $maxKeys = self::MAX_KEYS, string $continuationToken = ''): array
private function listObjects(string $prefix = '', int $maxKeys = self::MAX_PAGE_SIZE, string $continuationToken = ''): array
{
if ($maxKeys > self::MAX_KEYS) {
throw new Exception('Cannot list more than ' . self::MAX_KEYS . ' objects');
if ($maxKeys > self::MAX_PAGE_SIZE) {
throw new Exception('Cannot list more than '.self::MAX_PAGE_SIZE.' objects');
}

$uri = '/';
Expand Down Expand Up @@ -665,15 +667,15 @@ public function getPartitionTotalSpace(): float
* Get all files and directories inside a directory.
*
* @param string $dir Directory to scan
* @param int $keys
* @param int $max
* @param string $continuationToken
* @return array<mixed>
*
* @throws Exception
*/
public function getFiles(string $dir, int $keys = self::MAX_KEYS, string $continuationToken = ''): array
public function getFiles(string $dir, int $max = self::MAX_PAGE_SIZE, string $continuationToken = ''): array
{
$data = $this->listObjects($dir, $keys, $continuationToken);
$data = $this->listObjects($dir, $max, $continuationToken);

// Set to false if all the results were returned. Set to true if more keys are available to return.
$data['IsTruncated'] = $data['IsTruncated'] === 'true';
Expand Down

0 comments on commit 0bd69e1

Please sign in to comment.