deployer
deployer copied to clipboard
Dirname behaves differently on windows vs linux/mac
- Deployer version: v7.4.0
- Deployment OS: Windows
I know I see it in 7.2 but I am sure this has been an issue since the use of dirname for parsing configured paths.
Within deploy:shared dirname is used to parse shared_files.
https://github.com/deployphp/deployer/blob/88c59a8fa18c7f1b5a9565bbe3170d45cb84bf80/recipe/deploy/shared.php#L62
The issue is that dirname behaves based on the file system deployer runs from not the remote file system, which will result in some errors.
[dev] run if [ ! -d $(echo /home/user/deploy_test/releases/4/\) ]; then mkdir -p /home/user/deploy_test/releases/4/\;fi
[dev] bash: line 2: syntax error: unexpected end of file
[dev] error in shared.php on line 80:
[dev] exit code -1 (Unknown error)
For example if you are sharing a file /foo.php on windows the dirname is \ on linux/mac the dirname is /. (You can avoid this in some cases by not putting / at the front of your shared dirs and shared files)
windows:
PS C:\Users\foo> php -r "var_dump(dirname('/foo.php'));"
string(1) "\"
linux:
~ php -r "var_dump(dirname('/foo.php'));"
Command line code:1:
string(1) "/"
The dirname doc calls out this behavior: https://www.php.net/manual/en/function.dirname.php.
Unfortunately this makes dirname only be consistent if it being used on a path where the intended usage is the same system as the caller. Since deployer is using paths on a remote system, linux is assumed.
I see a few other usages of dirname within deployer. I think to be compatible with deploying from a windows operating system deployer will have to do its own dirname implementation.
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.
One option to still make use of dirname long as the functional usage of the paths are all intended for the remote machine by instead using a wrapping function like.
function getDirectory($file) {
$dirname = dirname($file);
return str_replace('\\', '/', $dirname);
}
We need to develop a separate set of function for only nix and use it.
This issue has been automatically closed. Please, open a discussion for bug reports and feature requests.
Read more: [https://github.com/deployphp/deployer/discussions/3888]