Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2909: Relative root paths no longer seem to work #4019

Merged
merged 6 commits into from
Mar 29, 2019
Merged

#2909: Relative root paths no longer seem to work #4019

merged 6 commits into from
Mar 29, 2019

Conversation

JTubex
Copy link
Contributor

@JTubex JTubex commented Mar 27, 2019

Describe the bug
#2909
When executing any drush command in a relative root path, the command times out and gives a segmentation fault.

To Reproduce
execute drush cr.

Expected behavior
A cache rebuild.

Actual behavior
The command timed out and gave a segmentation fault.

When executing drush cr -vvv the result was the following:

[preflight] Redispatch to site-local Drush: /var/www/..../htdocs/vendor/drush/drush/drush.
[preflight] Redispatch to site-local Drush: /var/www/..../htdocs/vendor/drush/drush/drush.
[preflight] Redispatch to site-local Drush: /var/www/..../htdocs/vendor/drush/drush/drush.
....

System Configuration

Q A
Drush version? 9.6.x. 9.5 still works
Drupal version? 8.6
PHP version 7.2
OS? Linux

@weitzman
Copy link
Member

Greg suggest Path::canonicalize() instead of realpath().

@JTubex
Copy link
Contributor Author

JTubex commented Mar 27, 2019

@weitzman, Path::canonicalize() did not resolve the issue.

The problem is that in Drush\Preflight\RedispatchToSiteLocal::redispatchIfSiteLocalDrush() $vendor is the absolute path and $root is the symlinked absolute path. So the check on rule 38 in Drush\Preflight\RedispatchToSiteLocal will fail because the symlinked path to drush is not the same as the real path to drush.

@weitzman
Copy link
Member

I just approved webflo/drupal-finder#40. Hopefully @webflo will merge it soon. Does that fix it for you?

@JTubex
Copy link
Contributor Author

JTubex commented Mar 28, 2019

@weitzman, The problem still occurs with the fix in webflo/drupal-finder#40.

@JTubex
Copy link
Contributor Author

JTubex commented Mar 28, 2019

@weitzman, I was able to find where the bug is located.

  1. e.g. Site is located in /var/www/release/1.0.0/htdocs
  2. Create a symlink /var/www/current -> /var/www/release/1.0.0
  3. The website is now accessible in /var/www/current/htdocs.
  4. Execute drush in /var/www/current/htdocs.

The problem occurs in repo Webflo/Drupal-finder.

In file DrupalFinder\DrupalFinder::locateRoot line 43 the check is_link will return FALSE because the webroot /var/www/current/htdocs is not a symlink, but /var/www/current is.

@JTubex
Copy link
Contributor Author

JTubex commented Mar 28, 2019

BTW: I created webflo/drupal-finder#41

@@ -34,7 +34,7 @@ class Environment
public function __construct($homeDir, $cwd, $autoloadFile)
{
$this->homeDir = $homeDir;
$this->originalCwd = Path::canonicalize($cwd);
$this->originalCwd = FsUtils::realpath($cwd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FsUtils::realpath is a lot safer than a raw realpath call, so perhaps this is okay. If we add this, it means that we'll have to work harder in the AppVeyor tests, because this will convert Windows paths from using / to \.

This only introduces a handful of failures in the current tests, so I suppose it is tractable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greg-1-anderson, I'm not sure what the right way is to fix the tests. Can you point me in the right direction? Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our typical strategy here is to normalize the output before asserting. For example, if you str_replace each \ with a /, then you can compare the path invariantly again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Let's see if this fixes the tests.

Copy link
Member

@greg-1-anderson greg-1-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 👍 on this; however, symlinks and realpath have caused us problems before, so let's get a second +1 from @weitzman before merging here before we decide whether we'll support it.

Copy link
Member

@weitzman weitzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canonicalized paths always have same slashes even on windows. So I don't immediately see why we need str replace.

@greg-1-anderson
Copy link
Member

This PR uses realpath rather than canonicalize. That is necessary, because this use-case involves symlinks. Symlinks and realpath have been problematic to support in the past, but perhaps might work out here.

@weitzman
Copy link
Member

That's fine. I'm arguing against the replace calls in tests. Instead, whatever is writing cwd to config should canonicalize first.

@JTubex
Copy link
Contributor Author

JTubex commented Mar 29, 2019

What about this change?

$this->originalCwd = Path::canonicalize(FsUtils::realpath($cwd));

@weitzman weitzman merged commit 95d0313 into drush-ops:master Mar 29, 2019
@weitzman
Copy link
Member

Thanks for your persistence, @JTubex.

@JTubex
Copy link
Contributor Author

JTubex commented Mar 29, 2019

Great!

pjcdawkins added a commit to pjcdawkins/platformsh-cli that referenced this pull request Nov 2, 2019
This was done for dedicated (Enterprise) environments (whose absolute app root
was not /app). Drush now supports relative paths (since 9.6.2) so this is
unnecessary.

Users whose dedicated (Enterprise) sites are on old versions of Drush 9 (i.e.
between 9.0.0 and 9.6.2) are advised to upgrade Drush to at least 9.6.2. 9.7.1
is the latest version at the time of writing.

See the Drush fix in drush-ops/drush#4019
pjcdawkins added a commit to pjcdawkins/platformsh-cli that referenced this pull request Nov 2, 2019
This was done for dedicated (Enterprise) environments (whose absolute app root
was not /app). Drush now supports relative paths (since 9.6.2) so this is
unnecessary.

Users whose dedicated (Enterprise) sites are on old versions of Drush 9 (i.e.
between 9.0.0 and 9.6.2) are advised to upgrade Drush to at least 9.6.2. 9.7.1
is the latest version at the time of writing.

See the Drush fix in drush-ops/drush#4019
pjcdawkins added a commit to platformsh/legacy-cli that referenced this pull request Nov 4, 2019
This was done for dedicated (Enterprise) environments (whose absolute app root
was not /app). Drush now supports relative paths (since 9.6.2) so this is
unnecessary.

Users whose dedicated (Enterprise) sites are on old versions of Drush 9 (i.e.
between 9.0.0 and 9.6.2) are advised to upgrade Drush to at least 9.6.2. 9.7.1
is the latest version at the time of writing.

See the Drush fix in drush-ops/drush#4019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants