From b8e3314417404e4e710ad4ab869e50ec3e5f0999 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Sat, 18 Feb 2023 17:32:06 +0100 Subject: [PATCH] Don't fail if directory exists on recursive creation --- src/Driver/EioFilesystemDriver.php | 7 +++++++ src/Driver/UvFilesystemDriver.php | 7 +++++++ test/FilesystemDriverTest.php | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Driver/EioFilesystemDriver.php b/src/Driver/EioFilesystemDriver.php index 6d3fe47..e629604 100644 --- a/src/Driver/EioFilesystemDriver.php +++ b/src/Driver/EioFilesystemDriver.php @@ -233,6 +233,13 @@ final class EioFilesystemDriver implements FilesystemDriver try { $deferred->getFuture()->await(); + } catch (FilesystemException $exception) { + $result = $this->getStatus($path); + if ($result !== null && ($result['mode'] & 0040000)) { + return; + } + + throw $exception; } finally { $this->poll->done(); } diff --git a/src/Driver/UvFilesystemDriver.php b/src/Driver/UvFilesystemDriver.php index cbb8112..34ac247 100644 --- a/src/Driver/UvFilesystemDriver.php +++ b/src/Driver/UvFilesystemDriver.php @@ -266,6 +266,13 @@ final class UvFilesystemDriver implements FilesystemDriver try { $deferred->getFuture()->await(); + } catch (FilesystemException $exception) { + $result = $this->getStatus($path); + if ($result !== null && ($result['mode'] & 0040000)) { + return; + } + + throw $exception; } finally { $this->poll->done(); } diff --git a/test/FilesystemDriverTest.php b/test/FilesystemDriverTest.php index f787cc8..c8d12fd 100644 --- a/test/FilesystemDriverTest.php +++ b/test/FilesystemDriverTest.php @@ -386,13 +386,20 @@ abstract class FilesystemDriverTest extends FilesystemTest $this->assertTrue($this->driver->exists($dir)); } - public function testCreateDirectoryRecursivelyExists(): void + public function testCreateDirectoryRecursivelyExistsDir(): void { $this->expectNotToPerformAssertions(); $this->driver->createDirectoryRecursively(__DIR__, 0764); } + public function testCreateDirectoryRecursivelyExistsFile(): void + { + $this->expectException(FilesystemException::class); + + $this->driver->createDirectoryRecursively(__FILE__, 0764); + } + public function testCreateDirectoryFailsOnNonexistentPath(): void { $fixtureDir = Fixture::path();