From 0c0202bcc4e022d19f16245a17105f806ac7041b Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 2 Dec 2025 09:11:32 +0530 Subject: [PATCH 1/2] Revert "Merge pull request #138 from utopia-php/fix-dir-exists" This reverts commit 5562a615ac50c790addf91a35da66fe92ac6accd, reversing changes made to 71102ea98c3f05b017d109a93980d0cb6b98c7ae. --- src/Storage/Device/S3.php | 26 ++++---------------------- tests/Storage/Device/LocalTest.php | 30 ------------------------------ tests/Storage/S3Base.php | 21 --------------------- 3 files changed, 4 insertions(+), 73 deletions(-) diff --git a/src/Storage/Device/S3.php b/src/Storage/Device/S3.php index cab37c82..c21bb9cb 100644 --- a/src/Storage/Device/S3.php +++ b/src/Storage/Device/S3.php @@ -616,7 +616,7 @@ public function deletePath(string $path): bool } /** - * Check if file or directory exists + * Check if file exists * * @param string $path * @return bool @@ -625,29 +625,11 @@ public function exists(string $path): bool { try { $this->getInfo($path); - - return true; } catch (\Throwable $th) { - try { - $root = $this->getRoot(); - if (str_starts_with($path, $root.'/') || str_starts_with($path, $root.'\\')) { - $prefix = $path; - } else { - $prefix = $root.'/'.ltrim($path, '/'); - } - - if (! empty($path) && ! str_ends_with($prefix, '/')) { - $prefix .= '/'; - } - - $objects = $this->listObjects($prefix, 1); - $count = (int) ($objects['KeyCount'] ?? 0); - - return $count > 0; - } catch (\Throwable $th2) { - return false; - } + return false; } + + return true; } /** diff --git a/tests/Storage/Device/LocalTest.php b/tests/Storage/Device/LocalTest.php index 124accec..c3d91b23 100644 --- a/tests/Storage/Device/LocalTest.php +++ b/tests/Storage/Device/LocalTest.php @@ -84,36 +84,6 @@ public function testFileExists() $this->object->delete($this->object->getPath('text-for-test-exists.txt')); } - public function testDirectoryExists() - { - $this->assertEquals(false, $this->object->exists($this->object->getPath('nonexistent-directory'))); - $this->assertEquals(false, $this->object->exists($this->object->getPath('nonexistent-directory/'))); - - $testDir = $this->object->getPath('test-directory-exists'); - $this->assertTrue($this->object->createDirectory($testDir)); - $this->assertEquals(true, $this->object->exists($testDir)); - $this->assertEquals(true, $this->object->exists($testDir.'/')); - - $nestedDir = $testDir.'/nested/deep/structure'; - $this->assertTrue($this->object->createDirectory($nestedDir)); - $this->object->write($nestedDir.'/test.txt', 'Hello World'); - - $this->assertEquals(true, $this->object->exists($testDir.'/nested')); - $this->assertEquals(true, $this->object->exists($testDir.'/nested/')); - $this->assertEquals(true, $this->object->exists($testDir.'/nested/deep')); - $this->assertEquals(true, $this->object->exists($testDir.'/nested/deep/')); - $this->assertEquals(true, $this->object->exists($nestedDir)); - $this->assertEquals(true, $this->object->exists($nestedDir.'/')); - - $this->assertEquals(true, $this->object->exists($nestedDir.'/test.txt')); - - $this->object->delete($testDir, true); - - $this->assertEquals(false, $this->object->exists($testDir)); - $this->assertEquals(false, $this->object->exists($testDir.'/nested')); - $this->assertEquals(false, $this->object->exists($nestedDir)); - } - public function testMove() { $this->assertEquals($this->object->write($this->object->getPath('text-for-move.txt'), 'Hello World'), true); diff --git a/tests/Storage/S3Base.php b/tests/Storage/S3Base.php index 338537a3..2218ce0c 100644 --- a/tests/Storage/S3Base.php +++ b/tests/Storage/S3Base.php @@ -144,27 +144,6 @@ public function testFileExists() $this->assertEquals(false, $this->object->exists($this->object->getPath('testing/kitten-5.jpg'))); } - public function testDirectoryExists() - { - $this->assertEquals(true, $this->object->exists($this->object->getPath('testing/'))); - - $this->assertEquals(false, $this->object->exists($this->object->getPath('nonexistent/'))); - - $this->object->write($this->object->getPath('nested/deep/structure/test.txt'), 'Hello World', 'text/plain'); - - $this->assertEquals(true, $this->object->exists($this->object->getPath('nested'))); - $this->assertEquals(true, $this->object->exists($this->object->getPath('nested/deep'))); - $this->assertEquals(true, $this->object->exists($this->object->getPath('nested/deep/structure'))); - - $this->assertEquals(true, $this->object->exists($this->object->getPath('nested/deep/structure/test.txt'))); - - $this->object->delete($this->object->getPath('nested/deep/structure/test.txt')); - - $this->assertEquals(false, $this->object->exists($this->object->getPath('nested'))); - $this->assertEquals(false, $this->object->exists($this->object->getPath('nested/deep'))); - $this->assertEquals(false, $this->object->exists($this->object->getPath('nested/deep/structure'))); - } - public function testMove() { $this->assertEquals(true, $this->object->write($this->object->getPath('text-for-move.txt'), 'Hello World', 'text/plain')); From 8ed1f047f3a4040f3dd4f259ccd5f81861c183b6 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 2 Dec 2025 11:12:04 +0530 Subject: [PATCH 2/2] trigger ci