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

Root relative paths in site aliases #2411

Closed
geek-merlin opened this issue Oct 24, 2016 · 12 comments
Closed

Root relative paths in site aliases #2411

geek-merlin opened this issue Oct 24, 2016 · 12 comments

Comments

@geek-merlin
Copy link
Contributor

geek-merlin commented Oct 24, 2016

When using a home-relative (important here) root path, the path is duplicated. Experienced on 8.1.6 and today's dev.

See "current/docroot/current/docroot" below.

$ drush rsync @project.live.default:%files @project.live-new.default:%files -v
You will delete files in user@host:current/docroot/current/docroot/sites/default/files and replace with data from user@oldhost:/foo/sites/default/files/
$ drush sa @project.live-new.default
$aliases["project.live-new.default"] = array (
  'uri' => 'http://uri',
  'root' => 'current/docroot',
  'remote-host' => 'host',
  'remote-user' => 'user',
);
@weitzman
Copy link
Member

Are you using latest dev on both sides of the rsync? Please post both sa --full for both aliases.

@geek-merlin
Copy link
Contributor Author

Lools like the root cause is in drush_sitealias_evaluate_path().

If i set %files explicitly to 'foo', the path is "corrent/docroot/current/docroot/foo".

@geek-merlin
Copy link
Contributor Author

Are you using latest dev on both sides of the rsync?

[renner@serpens docroot]$ drush @weinkauf.live-new.default version
Drush Version : 8.2-dev

[renner@serpens docroot]$ drush @weinkauf.live.default version
Drush Version : 8.1-dev

@geek-merlin
Copy link
Contributor Author

Please post both sa --full for both aliases.

$ drush sa @weinkauf.live-new.default --full
$aliases["weinkauf.live-new.default"] = array (
  'uri' => 'http://uri',
  'root' => 'current/docroot',
  'remote-host' => 'host.freistilbox.net',
  'remote-user' => 'user',
  'php' => 'php5.6',
);
$ drush sa @weinkauf.live.default --full
$aliases["weinkauf.live.default"] = array (
  'uri' => 'https://uri',
  'root' => '/app/public',
  'remote-host' => 'ssh.eu.platform.sh',
  'remote-user' => 'foo-master',
);

@geek-merlin
Copy link
Contributor Author

geek-merlin commented Oct 24, 2016

Debugging shows this is the code in drush_sitealias_evaluate_path() that does the duplication. Alas, i'm too far from groking the logic there to suggest a fix. (Also it looks like it needs a conceptual decision where to do the job)

  foreach ($full_path_aliases as $key => $value) {
    // Expand all relative path aliases to be based off of the Drupal root
    if (!drush_is_absolute_path($value, "LOCAL") && ($key != '%root')) {
      $full_path_aliases[$key] = $drupal_root . $value;
    }

$path = str_replace(array_keys($full_path_aliases), array_values($full_path_aliases), $path);

  // Next make the rsync path, which includes the machine
  // and path components together.
  // First make empty paths or relative paths start from the drupal root.
  if (empty($path) || (!drush_is_absolute_path($path, "LOCAL"))) {
    $path = $drupal_root . $path;
  }

EDIT: updated code.

@weitzman
Copy link
Member

This has come up in a few issues. Maybe @greg-1-anderson can spot the problem and know where to fix. Also see #2324

@greg-1-anderson
Copy link
Member

Drush does not support relative paths for root. Supporting relative paths here would be antithetical to the purpose of an alias, which is to provide a reference to a specific site that works regardless of your current working directory. I am not really in favor of officially making this a supported configuration; however, the workaround would be to call getcwd() in your alias file, and compose your own path in your alias. e.g. 'root' => getcwd() . '/current/docroot',.

I also think that the workaround is a bad idea, but it would work as well as could be expected (which IMO is not very well).

@weitzman
Copy link
Member

weitzman commented Oct 25, 2016 via email

@greg-1-anderson
Copy link
Member

I think that failing fast might be appropriate here; however, the guard would have to be well-placed. --root on the command line might be relative, and that should be allowed. It might be overly diligent to stop execution for any alias merely loaded that contains a relative document root; besides, some might choose to store their alias roots as relative paths, and then use an alias alter hook to provide the base path. So, if such a check is included, it would have to be right before the alias was used, after it was altered. I'm not convinced it's worth the effort to do it at this point. Maybe the object-oriented implementation of aliases could have a validate method that could do tests like this.

@geek-merlin
Copy link
Contributor Author

Drush does not support relative paths for root.
SSH treats them as relative to user-root, and i use them with many other drush commands.
(It's just this case that fails.)
And if we remove one of the two duplicate code blocks mentioned above, then rsync will do too.

I'd request keeping this behavior as it can strongly simplify aliases. (I have providers here that have no less than 7 path components in a user-root =:-() And the server knows its user-root so why duplicate that.)

@greg-1-anderson
Copy link
Member

You'd be better off changing your aliases to use 'root' => getcwd() . '/current/docroot',, in case Drush rejects relative roots in the future.

I'm not in a big hurry to break this feature, though.

@weitzman weitzman changed the title Root path duplicated Root relative paths in site aliases Dec 26, 2016
@greg-1-anderson
Copy link
Member

Old issue; closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants