From 3f81e20d15e2ef34d9caf4a69b415f591a93f76c Mon Sep 17 00:00:00 2001 From: Alexander Strizhak Date: Mon, 14 Oct 2024 23:52:53 +0300 Subject: [PATCH 1/2] [WebDAV] createDirectory - not throw if got 405 (The resource you tried to create already exists) --- src/WebDAV/WebDAVAdapter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/WebDAV/WebDAVAdapter.php b/src/WebDAV/WebDAVAdapter.php index 935972692..ac5f08e03 100644 --- a/src/WebDAV/WebDAVAdapter.php +++ b/src/WebDAV/WebDAVAdapter.php @@ -233,6 +233,10 @@ public function createDirectory(string $path, Config $config): void throw UnableToCreateDirectory::dueToFailure($path, $exception); } + if ($response['statusCode'] === 405) { + continue; + } + if ($response['statusCode'] !== 201) { throw UnableToCreateDirectory::atLocation($path, 'Failed to create directory at: ' . $location); } From 1eb13cba7ec0b1e6ba2bcebd994530dce649d403 Mon Sep 17 00:00:00 2001 From: Alexander Strizhak Date: Tue, 15 Oct 2024 00:15:22 +0300 Subject: [PATCH 2/2] add test case for 405 --- src/WebDAV/WebDAVAdapterTestCase.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/WebDAV/WebDAVAdapterTestCase.php b/src/WebDAV/WebDAVAdapterTestCase.php index 7b3d2904d..d8a06a3ad 100644 --- a/src/WebDAV/WebDAVAdapterTestCase.php +++ b/src/WebDAV/WebDAVAdapterTestCase.php @@ -9,6 +9,7 @@ use League\Flysystem\UnableToMoveFile; use League\Flysystem\UnableToSetVisibility; use League\Flysystem\Visibility; +use Sabre\DAV\Client; abstract class WebDAVAdapterTestCase extends FilesystemAdapterTestCase { @@ -48,7 +49,7 @@ public function creating_a_directory_with_leading_and_trailing_slashes(): void { $this->runScenario(function () { $adapter = $this->adapter(); - $adapter->createDirectory('/some/directory/', new Config); + $adapter->createDirectory('/some/directory/', new Config()); self::assertTrue($adapter->directoryExists('/some/directory/')); }); @@ -132,4 +133,28 @@ public function moving_a_file_that_does_not_exist(): void $this->adapter()->move('source.txt', 'destination.txt', new Config()); }); } + + /** + * @test + */ + public function part_of_prefix_already_exists(): void + { + $this->runScenario(function () { + $config = new Config(); + + $adapter1 = new WebDAVAdapter( + new Client(['baseUri' => 'http://localhost:4040/']), + 'directory1/prefix1', + ); + $adapter1->createDirectory('folder1', $config); + self::assertTrue($adapter1->directoryExists('/folder1')); + + $adapter2 = new WebDAVAdapter( + new Client(['baseUri' => 'http://localhost:4040/']), + 'directory1/prefix2', + ); + $adapter2->createDirectory('folder2', $config); + self::assertTrue($adapter2->directoryExists('/folder2')); + }); + } }