Skip to content

Commit

Permalink
Check directory exists with minimum max keys (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
zingimmick authored Mar 6, 2022
1 parent 81590a4 commit e204eb5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ObsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public function directoryExists(string $path): bool
'Bucket' => $this->bucket,
'Prefix' => $prefix,
'Delimiter' => '/',
'MaxKeys' => 1,
];
$model = $this->client->listObjects($options);

Expand Down Expand Up @@ -434,6 +435,7 @@ public function lastModified(string $path): FileAttributes
protected function getObject(string $path): StreamInterface
{
try {
/** @var array{Body: \Psr\Http\Message\StreamInterface} $model */
$model = $this->client->getObject([
'Bucket' => $this->bucket,
'Key' => $this->pathPrefixer->prefixPath($path),
Expand Down Expand Up @@ -471,6 +473,7 @@ public function listDirObjects(string $dirname = '', bool $recursive = false): a
while (true) {
$options['Marker'] = $nextMarker;

/** @var array{Contents: array<array{Key: string|null, Prefix: string|null, ContentLength?: int, Size?: int, LastModified?: string, ContentType?: string}>|null, CommonPrefixes: array<array<string, string>>|null, NextMarker: ?string} $model */
$model = $this->client->listObjects($options);

$nextMarker = $model['NextMarker'];
Expand Down Expand Up @@ -595,6 +598,7 @@ public function signUrl(string $path, $expiration, array $options = [], string $
{
$expires = $expiration instanceof DateTimeInterface ? $expiration->getTimestamp() - time() : $expiration;

/** @var array{SignedUrl: string} $model */
$model = $this->client->createSignedUrl([
'Method' => $method,
'Bucket' => $this->bucket,
Expand Down
2 changes: 2 additions & 0 deletions tests/MockAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function testCreateDir(): void
'Bucket' => 'test',
'Prefix' => 'path/',
'Delimiter' => '/',
'MaxKeys' => 1,
],
])->andReturn(
new Model([
Expand Down Expand Up @@ -1070,6 +1071,7 @@ public function testDirectoryExists(): void
'Bucket' => 'test',
'Prefix' => 'fixture/exists-directory/',
'Delimiter' => '/',
'MaxKeys' => 1,
],
])->andReturn(new Model([
'ContentLength' => '302',
Expand Down

0 comments on commit e204eb5

Please sign in to comment.