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.

CommentFileSizeAuthor
#6 absolute-paths.patch2.37 KBgreg.1.anderson
drush-dd-windows.patch1015 byteskulov
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kulov’s picture

Status: Active » Needs review
moshe weitzman’s picture

Could 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.

greg.1.anderson’s picture

It 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.

kulov’s picture

I 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.

greg.1.anderson’s picture

Assigned: Unassigned » greg.1.anderson
Issue tags: +Windows

Today 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.

greg.1.anderson’s picture

FileSize
2.37 KB

Working 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?

kulov’s picture

Looks better.
Shouldn't that drush_is_absolute_path also use DIRECTORY_SEPARATOR?

kulov’s picture

on your question...

WinOS always return C:\. However it can also parse C:/ in case someone used it.

greg.1.anderson’s picture

Status: Needs review » Needs work

No, 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.

greg.1.anderson’s picture

I 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?

kulov’s picture

though 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

greg.1.anderson’s picture

Status: Needs work » Closed (duplicate)