Skip to content

Commit 0c7b8ad

Browse files
authored
Merge pull request #145 from utopia-php/revert-exists-dir-0.18.x
2 parents 4f14ec9 + e926ae9 commit 0c7b8ad

File tree

3 files changed

+4
-73
lines changed

3 files changed

+4
-73
lines changed

src/Storage/Device/S3.php

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

557557
/**
558-
* Check if file or directory exists
558+
* Check if file exists
559559
*
560560
* @param string $path
561561
* @return bool
@@ -564,29 +564,11 @@ public function exists(string $path): bool
564564
{
565565
try {
566566
$this->getInfo($path);
567-
568-
return true;
569567
} catch (\Throwable $th) {
570-
try {
571-
$root = $this->getRoot();
572-
if (str_starts_with($path, $root.'/') || str_starts_with($path, $root.'\\')) {
573-
$prefix = $path;
574-
} else {
575-
$prefix = $root.'/'.ltrim($path, '/');
576-
}
577-
578-
if (! empty($path) && ! str_ends_with($prefix, '/')) {
579-
$prefix .= '/';
580-
}
581-
582-
$objects = $this->listObjects($prefix, 1);
583-
$count = (int) ($objects['KeyCount'] ?? 0);
584-
585-
return $count > 0;
586-
} catch (\Throwable $th2) {
587-
return false;
588-
}
568+
return false;
589569
}
570+
571+
return true;
590572
}
591573

592574
/**

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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -144,27 +144,6 @@ public function testFileExists()
144144
$this->assertEquals(false, $this->object->exists($this->object->getPath('testing/kitten-5.jpg')));
145145
}
146146

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-
168147
public function testMove()
169148
{
170149
$this->assertEquals(true, $this->object->write($this->object->getPath('text-for-move.txt'), 'Hello World', 'text/plain'));

0 commit comments

Comments
 (0)