From 14c198c48dca736db569eccb6964843c16c5ec40 Mon Sep 17 00:00:00 2001 From: "Saad M." Date: Thu, 2 Oct 2025 12:23:03 +0200 Subject: [PATCH 1/2] feat(gcs): support filename prefix filtering in listContents --- src/GoogleCloudStorage/GoogleCloudStorageAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php index a8b1b5a03..dd7aa0cec 100644 --- a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php +++ b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php @@ -311,7 +311,7 @@ public function listContents(string $path, bool $deep): iterable $prefixes = $options = []; if ( ! empty($prefixedPath)) { - $options = ['prefix' => sprintf('%s/', rtrim($prefixedPath, '/'))]; + $options = ['prefix' => $prefixedPath]; } if ($deep === false) { From 57daa4ced8370ebc42fc3972bc9843de7907af72 Mon Sep 17 00:00:00 2001 From: "Saad M." Date: Fri, 10 Oct 2025 17:57:50 +0200 Subject: [PATCH 2/2] feat(GCS): add optional listContentsAsPrefix flag to enable prefix-based listing --- src/GoogleCloudStorage/GoogleCloudStorageAdapter.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php index dd7aa0cec..790fedb5b 100644 --- a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php +++ b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php @@ -305,13 +305,16 @@ public function storageObjectToStorageAttributes(StorageObject $object): Storage return new FileAttributes($path, $fileSize, null, $lastModified, $mimeType, $info); } - public function listContents(string $path, bool $deep): iterable + public function listContents(string $path, bool $deep, array $options = []): iterable { + $asPrefix = $options['listContentsAsPrefix'] ?? false; + $prefixedPath = $this->prefixer->prefixPath($path); - $prefixes = $options = []; - if ( ! empty($prefixedPath)) { + if ($asPrefix) { $options = ['prefix' => $prefixedPath]; + } elseif (!empty($prefixedPath)) { + $options = ['prefix' => sprintf('%s/', rtrim($prefixedPath, '/'))]; } if ($deep === false) {