wp-cli / dist-archive-command

Create a distribution .zip or .tar.gz based on a plugin or theme's .distignore file
https://developer.wordpress.org/cli/commands/dist-archive/
MIT License
48 stars 24 forks source link

Path errors when running `wp dist-archive` on Windows #76

Closed VoHoTv closed 6 months ago

VoHoTv commented 1 year ago

Hi there! When running the wp dist-archive command I am getting the following erorr:

"Target directory does not exist: C:\Users\USER\Local Sites\het-lokaal\app\public\wp-content\themes\lokaal/C:\Users\USER\Local Sites\het-lokaal\app\public\wp-content\themes\lokaal/C:\Users\USER\Local Sites\het-lokaal\app\public\wp-content\themes"

Is this some kind of misconfiguration on my system? Or am I missing some parameter? Thank you so much!

image

danielbachhuber commented 1 year ago

Thanks for the report, @VoHoTv !

Is this some kind of misconfiguration on my system? Or am I missing some parameter? Thank you so much!

There are a lot of hardcoded / references in wp dist-archive 🙈

https://github.com/wp-cli/dist-archive-command/blob/8fb85d012cd493a778006b6cfec8280532d68faf/src/Dist_Archive_Command.php#L86-L97

I think the path breaking is building on Windows.

Maybe it's as simple as replacing the '/' references with DIRECTORY_SEPARATOR ?

Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.

costdev commented 1 year ago

Looks like there's a couple of things going on here:

  1. It's trying to detect / when the separator could be \.
  2. It assumes the only absolute path is one beginning with a separator, which would be true for *nix/Windows Network Shares. However, on local Windows paths is DRIVE_LETTER:\...

Take a look at what wp_normalize_path() and path_is_absolute() do. WordPress Core commonly uses these in similar scenarios.

VoHoTv commented 1 year ago

@costdev Just did some tests and when I replace the current conditions which check if it's an absolute path:

"if ( 0 !== strpos( $path, '/' ) ) {}" and "if ( 0 !== strpos( $archive_path, '/' ) ) {}"

And replace it with a copy of the 2 functions you mentioned it works indeed.

shamimipt commented 1 year ago

Hi There, I am fetching the same issue. Is it fixed or Not?

danielbachhuber commented 1 year ago

@shamimipt It's not fixed, no. Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.

I think we'll also want to get tests running on Windows https://github.com/wp-cli/wp-cli-tests/issues/155

danielbachhuber commented 10 months ago

@VoHoTv @shamimipt Can you install the wp dist-archive main branch and see if https://github.com/wp-cli/dist-archive-command/pull/81 resolves your issue on Windows?

shamimipt commented 10 months ago

@VoHoTv Thank you so much.