Skip to content

Conversation

@Runnin4ik
Copy link

This PR fixes a bug in UvFilesystemDriver::createDirectoryRecursively where creating directories with absolute paths on Windows failed with uv error Could not create directory.

The Issue

The current implementation unconditionally prepends DIRECTORY_SEPARATOR to every path chunk derived from explode().

  1. On Windows:
    An absolute path like E:\Project explodes into ['E:', 'Project'].
    The loop immediately prepends a separator to the first element:
    $tmpPath becomes \E: (instead of just E:).

    While PHP's mkdir might handle this, the low-level uv_fs_mkdir function treats \E: as an invalid path on Windows, causing the operation to fail immediately.

  2. On Linux:
    An absolute path like /var/www explodes into ['', 'var', 'www'].
    The loop turns the first empty element into /.
    Then it appends the next element with a separator: //var.
    Since Linux treats double slashes (//) as a single slash, the bug was masked and the code worked by accident.

The Fix

I modified the loop logic to correctly handle the separator appending:

  • Windows: E: stays E: (no leading slash).
  • Linux: /var stays /var (leading slash preserved, no double slashes).

Verification

Tested locally on Windows 11 with PHP 8.5.1 and ext-uv. Directory creation now works correctly with absolute paths.

@Runnin4ik Runnin4ik changed the title Fix invalid absolute path construction on Windows Fix invalid path construction in createDirectoryRecursively on Windows Jan 19, 2026
@kelunik
Copy link
Member

kelunik commented Jan 19, 2026

Hi @Runnin4ik, thank you for the analysis and the fix! Could you add something to the tests?

- Adds a test case using sys_get_temp_dir() to verify that createDirectoryRecursively handles absolute paths correctly on Windows (e.g. 'C:\...') and Linux.

This ensures the fix for the invalid path construction is verified and prevents future regressions.
@Runnin4ik
Copy link
Author

Hi @Runnin4ik, thank you for the analysis and the fix! Could you add something to the tests?

Hi @kelunik, I've added the requested test case covering absolute paths.
It verifies the fix on Windows and ensures no regressions on Linux.

}

$parent = \dirname($dir);
if ($parent !== $baseDir && \str_starts_with($parent, $baseDir) && $driver->getStatus($parent)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the checks here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added them as a safeguard to ensure we don't accidentally delete the system temp directory, but I agree they are redundant here. I will simplify the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants