Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from cedricziel/issue-11
Browse files Browse the repository at this point in the history
Adapter::has should check if a directory object exists
  • Loading branch information
cedricziel authored Feb 2, 2021
2 parents 8d5a31e + e7c3379 commit f6cb1e4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/GoogleCloudStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,13 @@ public function has($path)
$path = $this->applyPathPrefix($path);
$object = $this->bucket->object($path);

return $object->exists();
if ($object->exists()) {
return true;
}

// flysystem strips trailing slashes so we need to check
// for directory objects
return $this->bucket->object(sprintf('%s/', $path))->exists();
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/GoogleCloudStorageAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,26 @@ public function testUrlCanBeCreated(): void

self::assertEquals(sprintf('%s/%s/%s', GoogleCloudStorageAdapter::GCS_BASE_URL, $adapterConfig['bucket'], $objectName), $url);
}

/**
* @see https://github.com/cedricziel/flysystem-gcs/issues/11
*
* @covers \CedricZiel\FlysystemGcs\GoogleCloudStorageAdapter::has()
*/
public function testHasWorksCorrectlyForDirectories(): void
{
$testId = uniqid('', true);
$adapterConfig = [
'bucket' => $this->bucket,
'projectId' => $this->project,
];

$directoryName = sprintf('%s', sprintf('icon-%s', $testId));

$adapter = new GoogleCloudStorageAdapter(null, $adapterConfig);
$fs = new Filesystem($adapter);
$fs->createDir($directoryName);

self::assertTrue($fs->has($directoryName));
}
}

0 comments on commit f6cb1e4

Please sign in to comment.