Skip to content

Commit 7d93e74

Browse files
authored
Merge pull request #74 from tinect/fix/solveFileExistanceCheck
2 parents 228cfb3 + 61f5c31 commit 7d93e74

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

src/BunnyCDNAdapter.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ public function delete($path): void
478478
*/
479479
public function directoryExists(string $path): bool
480480
{
481-
return $this->fileExists($path);
481+
return $this->exists(StorageAttributes::TYPE_DIRECTORY, $path);
482482
}
483483

484484
/**
@@ -487,16 +487,7 @@ public function directoryExists(string $path): bool
487487
*/
488488
public function fileExists(string $path): bool
489489
{
490-
$list = new DirectoryListing($this->listContents(
491-
Util::splitPathIntoDirectoryAndFile($path)['dir'],
492-
false
493-
));
494-
495-
$count = $list->filter(function (StorageAttributes $item) use ($path) {
496-
return Util::normalizePath($item->path()) === Util::normalizePath($path);
497-
})->toArray();
498-
499-
return (bool) count($count);
490+
return $this->exists(StorageAttributes::TYPE_FILE, $path);
500491
}
501492

502493
/**
@@ -559,4 +550,18 @@ private static function parse_bunny_timestamp(string $timestamp): int
559550
{
560551
return (date_create_from_format('Y-m-d\TH:i:s.u', $timestamp) ?: date_create_from_format('Y-m-d\TH:i:s', $timestamp))->getTimestamp();
561552
}
553+
554+
private function exists(string $type, string $path): bool
555+
{
556+
$list = new DirectoryListing($this->listContents(
557+
Util::splitPathIntoDirectoryAndFile($path)['dir'],
558+
false
559+
));
560+
561+
$count = $list->filter(function (StorageAttributes $item) use ($path, $type) {
562+
return $item->type() === $type && Util::normalizePath($item->path()) === Util::normalizePath($path);
563+
})->toArray();
564+
565+
return (bool) count($count);
566+
}
562567
}

tests/FlysystemAdapterTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,36 @@ public function generating_a_temporary_url(): void
7575
$this->markTestSkipped('No temporary URL support is provided for BunnyCDN');
7676
}
7777

78+
/**
79+
* @test
80+
*/
81+
public function file_exists_on_directory_is_false(): void
82+
{
83+
$this->runScenario(function () {
84+
$adapter = $this->adapter();
85+
86+
$this->assertFalse($adapter->directoryExists('test'));
87+
$adapter->createDirectory('test', new Config());
88+
$this->assertTrue($adapter->directoryExists('test'));
89+
$this->assertFalse($adapter->fileExists('test'));
90+
});
91+
}
92+
93+
/**
94+
* @test
95+
*/
96+
public function directory_exists_on_file_is_false(): void
97+
{
98+
$this->runScenario(function () {
99+
$adapter = $this->adapter();
100+
101+
$this->assertFalse($adapter->fileExists('test.txt'));
102+
$adapter->write('test.txt', 'aaa', new Config());
103+
$this->assertTrue($adapter->fileExists('test.txt'));
104+
$this->assertFalse($adapter->directoryExists('test.txt'));
105+
});
106+
}
107+
78108
/**
79109
* @test
80110
*/

0 commit comments

Comments
 (0)