Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When running on Windows, function drush_sitealias_evaluate_path() incorrectly concatenates drupal root path and site path resulting in duplicated path value. This comes from because of incorrect assumption that absolute site path starts with slash. On Windows absolute paths are in format Drive:/path/to/site.
Additional verification clause is added in attached patch so path concatenation is only done when both path values are different from each other.
Comment | File | Size | Author |
---|---|---|---|
#6 | absolute-paths.patch | 2.37 KB | greg.1.anderson |
drush-dd-windows.patch | 1015 bytes | kulov |
Comments
Comment #1
kulov CreditAttribution: kulov commentedComment #2
moshe weitzman CreditAttribution: moshe weitzman commentedCould we not do $path == $drupal_root and skip the substr_compare? That would be more readable. Maybe add a trim() if we don't want a trailing slash or something? Just hoping to make it more readable.
Comment #3
greg.1.anderson CreditAttribution: greg.1.anderson commentedIt was originally my idea (in an email exchange) to do the substr compare, but I'm kind of torn about it. On the one hand, the "[A-Z]:\" test in Windows might be better (tho you need to also account for "[A-Z]:/" in php), since it is possible that there are other full paths that may be specified here that are not the Drupal root. However, the downside is, what if someone happens to have a file that really does begin C:\something on Linux? Maybe we should just allow that to fail, and do "the right thing" on Windows. The "right thing", regrettably, is to test for the drive letter plus a colon, I think.
Comment #4
kulov CreditAttribution: kulov commentedI do not see a scenario where if both paths are equal, they should be concatenated. That's why avoiding concatenation in this condition makes sense to me.
Comment #5
greg.1.anderson CreditAttribution: greg.1.anderson commentedToday I'm thinking we should just do this as moshe suggests in #2 (original path w/ 'trim' to remove trailing slash). We'll need to trim the PATH_SEPARATOR, so this related to #1103038: DIRECTORY_SEPARATOR causes errors on Windows running CygWin/Msys/Git shell.
Comment #6
greg.1.anderson CreditAttribution: greg.1.anderson commentedWorking through this today, I realized that I was mistaken in #5, and right back in #3. The absolute paths in question might be completely unrelated to the Drupal root; therefore, the patch in #0 is an insufficient test.
Attached is a patch that tests for absolute paths differently based on the platform; the state of the code has improved since #3, and there is now an $os variable that indicates the target platform (assumes that it is the same as the source platform unless specified in the alias record). In this scenario, testing for C:\ is not so bad.
I do not currently test for C:/. Is this necessary? In Powershell, it seems it should always be C:\, and in cygwin it would be /cygdrive. Thoughts?
Comment #7
kulov CreditAttribution: kulov commentedLooks better.
Shouldn't that
drush_is_absolute_path
also use DIRECTORY_SEPARATOR?Comment #8
kulov CreditAttribution: kulov commentedon your question...
WinOS always return C:\. However it can also parse C:/ in case someone used it.
Comment #9
greg.1.anderson CreditAttribution: greg.1.anderson commentedNo, drush_is_absolute_path should not use DIRECTORY_SEPARATOR. If $os indicated that the remote system was Windows, then we still want to compare for ":\\" even if the local system is Linux (in which case DIRECTORY_SEPARATOR would be "/").
This does bring up an important point, though; anywhere that we have a variable $os (a remote path might be involved), then we are going to need to call drush_directory_separator($os), because we might be working on a path for a different system than the one we're running on.
I'll review all of the places where that happens in a little bit.
Comment #10
greg.1.anderson CreditAttribution: greg.1.anderson commentedI guess on the Windows side, we should allow / or \ for drush_is_absolute_path. What if we need to trim the last directory separator on Windows? Should we always trim / and \ in case someone typed a "/" in Powershell?
Comment #11
kulov CreditAttribution: kulov commentedthough unlikely, it is possible due to the mixed environment nature of this project
so to be safe we should check both / and \ as separator on windows side
Comment #12
greg.1.anderson CreditAttribution: greg.1.anderson commentedI merged this into #766080: Windows support for drush: escaping the path to drush in backend invoke and elsewhere too, along with the suggestion from #11.