diff --git a/src/Driver/UvFilesystemDriver.php b/src/Driver/UvFilesystemDriver.php index 585f7ec..b58f179 100644 --- a/src/Driver/UvFilesystemDriver.php +++ b/src/Driver/UvFilesystemDriver.php @@ -216,7 +216,8 @@ public function createDirectoryRecursively(string $path, int $mode = 0777): void $mode, $deferred ): void { - $tmpPath .= DIRECTORY_SEPARATOR . \array_shift($arrayPath); + $part = \array_shift($arrayPath); + $tmpPath .= ($tmpPath !== '' || $part === '' ? DIRECTORY_SEPARATOR : '') . $part; if (empty($arrayPath)) { \uv_fs_mkdir( diff --git a/test/Driver/UvFilesystemDriverTest.php b/test/Driver/UvFilesystemDriverTest.php index 89519ce..86dfb13 100644 --- a/test/Driver/UvFilesystemDriverTest.php +++ b/test/Driver/UvFilesystemDriverTest.php @@ -37,4 +37,32 @@ protected function createDriver(): File\FilesystemDriver return new UvFilesystemDriver($loop); } + + public function testCreateDirectoryRecursivelyWithAbsolutePath(): void + { + $driver = $this->createDriver(); + + $baseDir = \sys_get_temp_dir(); + + $dir = $baseDir . DIRECTORY_SEPARATOR . 'amp-test-' . \uniqid('', true) . DIRECTORY_SEPARATOR . 'nested'; + + try { + $driver->createDirectoryRecursively($dir); + $status = $driver->getStatus($dir); + $this->assertNotNull($status, 'Directory should exist'); + + $isDir = ($status['mode'] & \UV::S_IFDIR) !== 0; + $this->assertTrue($isDir, 'Path must be a directory'); + + } finally { + if ($driver->getStatus($dir)) { + $driver->deleteDirectory($dir); + } + + $parent = \dirname($dir); + if ($driver->getStatus($parent)) { + $driver->deleteDirectory($parent); + } + } + } }