Skip to content

Commit 770593b

Browse files
committed
Revert "Merge pull request #138 from utopia-php/fix-dir-exists"
This reverts commit 5562a61, reversing changes made to 71102ea.
1 parent 10fe0c0 commit 770593b

File tree

3 files changed

+4
-78
lines changed

3 files changed

+4
-78
lines changed

src/Storage/Device/S3.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ public function deletePath(string $path): bool
616616
}
617617

618618
/**
619-
* Check if file or directory exists
619+
* Check if file exists
620620
*
621621
* @param string $path
622622
* @return bool
@@ -625,29 +625,11 @@ public function exists(string $path): bool
625625
{
626626
try {
627627
$this->getInfo($path);
628-
629-
return true;
630628
} catch (\Throwable $th) {
631-
try {
632-
$root = $this->getRoot();
633-
if (str_starts_with($path, $root.'/') || str_starts_with($path, $root.'\\')) {
634-
$prefix = $path;
635-
} else {
636-
$prefix = $root.'/'.ltrim($path, '/');
637-
}
638-
639-
if (! empty($path) && ! str_ends_with($prefix, '/')) {
640-
$prefix .= '/';
641-
}
642-
643-
$objects = $this->listObjects($prefix, 1);
644-
$count = (int) ($objects['KeyCount'] ?? 0);
645-
646-
return $count > 0;
647-
} catch (\Throwable $th2) {
648-
return false;
649-
}
629+
return false;
650630
}
631+
632+
return true;
651633
}
652634

653635
/**

tests/Storage/Device/LocalTest.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,36 +84,6 @@ public function testFileExists()
8484
$this->object->delete($this->object->getPath('text-for-test-exists.txt'));
8585
}
8686

87-
public function testDirectoryExists()
88-
{
89-
$this->assertEquals(false, $this->object->exists($this->object->getPath('nonexistent-directory')));
90-
$this->assertEquals(false, $this->object->exists($this->object->getPath('nonexistent-directory/')));
91-
92-
$testDir = $this->object->getPath('test-directory-exists');
93-
$this->assertTrue($this->object->createDirectory($testDir));
94-
$this->assertEquals(true, $this->object->exists($testDir));
95-
$this->assertEquals(true, $this->object->exists($testDir.'/'));
96-
97-
$nestedDir = $testDir.'/nested/deep/structure';
98-
$this->assertTrue($this->object->createDirectory($nestedDir));
99-
$this->object->write($nestedDir.'/test.txt', 'Hello World');
100-
101-
$this->assertEquals(true, $this->object->exists($testDir.'/nested'));
102-
$this->assertEquals(true, $this->object->exists($testDir.'/nested/'));
103-
$this->assertEquals(true, $this->object->exists($testDir.'/nested/deep'));
104-
$this->assertEquals(true, $this->object->exists($testDir.'/nested/deep/'));
105-
$this->assertEquals(true, $this->object->exists($nestedDir));
106-
$this->assertEquals(true, $this->object->exists($nestedDir.'/'));
107-
108-
$this->assertEquals(true, $this->object->exists($nestedDir.'/test.txt'));
109-
110-
$this->object->delete($testDir, true);
111-
112-
$this->assertEquals(false, $this->object->exists($testDir));
113-
$this->assertEquals(false, $this->object->exists($testDir.'/nested'));
114-
$this->assertEquals(false, $this->object->exists($nestedDir));
115-
}
116-
11787
public function testMove()
11888
{
11989
$this->assertEquals($this->object->write($this->object->getPath('text-for-move.txt'), 'Hello World'), true);

tests/Storage/S3Base.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ abstract protected function getAdapterName(): string;
2020
*/
2121
abstract protected function getAdapterDescription(): string;
2222

23-
/**
24-
* @return string
25-
*/
26-
abstract protected function getAdapterType(): string;
27-
2823
/**
2924
* @var S3
3025
*/
@@ -144,27 +139,6 @@ public function testFileExists()
144139
$this->assertEquals(false, $this->object->exists($this->object->getPath('testing/kitten-5.jpg')));
145140
}
146141

147-
public function testDirectoryExists()
148-
{
149-
$this->assertEquals(true, $this->object->exists($this->object->getPath('testing/')));
150-
151-
$this->assertEquals(false, $this->object->exists($this->object->getPath('nonexistent/')));
152-
153-
$this->object->write($this->object->getPath('nested/deep/structure/test.txt'), 'Hello World', 'text/plain');
154-
155-
$this->assertEquals(true, $this->object->exists($this->object->getPath('nested')));
156-
$this->assertEquals(true, $this->object->exists($this->object->getPath('nested/deep')));
157-
$this->assertEquals(true, $this->object->exists($this->object->getPath('nested/deep/structure')));
158-
159-
$this->assertEquals(true, $this->object->exists($this->object->getPath('nested/deep/structure/test.txt')));
160-
161-
$this->object->delete($this->object->getPath('nested/deep/structure/test.txt'));
162-
163-
$this->assertEquals(false, $this->object->exists($this->object->getPath('nested')));
164-
$this->assertEquals(false, $this->object->exists($this->object->getPath('nested/deep')));
165-
$this->assertEquals(false, $this->object->exists($this->object->getPath('nested/deep/structure')));
166-
}
167-
168142
public function testMove()
169143
{
170144
$this->assertEquals(true, $this->object->write($this->object->getPath('text-for-move.txt'), 'Hello World', 'text/plain'));

0 commit comments

Comments
 (0)