cp -r causes issues with symlinks on MacOS
mrsdizzie opened this issue · comments
This function is used in a lot of the tests:
wp-cli-tests/src/Context/FeatureContext.php
Lines 826 to 828 in c2d228b
On MacOS I have tests that fail with errors like:
--- Failed steps:
001 Scenario: Composer stack with both WordPress and wp-cli as dependencies (command line) # features/bootstrap.feature:321
And a dependency on current wp-cli # features/bootstrap.feature:323
$ cp -r '/Users/isla/source/wp-cli-dev/wp-cli'/* '/var/folders/v6/gqkd9_rd74171hsndwtjrxww0000gn/T/wp-cli-composer-local-652be01cc7a8d9.06666196/'
cp: vendor/rmccue: No such file or directory
cp: vendor/wp-cli/wp-cli-tests/vendor/rmccue: No such file or directory
cp: vendor/wp-cli/wp-cli-tests/vendor/wp-cli: directory causes a cycle
cp: vendor/wp-cli/find-command/vendor/rmccue: No such file or directory
cp: vendor/wp-cli/find-command/vendor/wp-cli: directory causes a cycle
cp: vendor/wp-cli/media-command/vendor/rmccue: No such file or directory
etc...
I believe this is caused by trying to copy symlinks around, as discussed here: https://unix.stackexchange.com/questions/500379/cp-works-differently-on-a-mac
I thought I could get around this by installing GNU cp from homebrew, but it doesn't work because even though I have it in my PATH
, I think wp-cli is setting an empty ENV here:
https://github.com/wp-cli/wp-cli/blob/main/php/WP_CLI/Process.php#L52-L60
I'm not exactly sure what the solution is, but just want to document it here. Options seem to be:
- Passing ENV along in the
Process::create
call and having users install GNU cp - Use
cp -a instead
- Something else that doesn't invlove using lots of symlinks?
Thanks for the report, @mrsdizzie !
I think the fix can be as simple as a conditional based on PHP_OS
: #183
We have some of these conditionals elsewhere (see use of is_windows()
), so I think it's fine to use another in this case.