The provisionFileSystem::symlink() method appears to use its parameters differently than its documentation and parameter names indicate.

Below, I've included the method as it currently appears. It takes a moment to realize that $target is being used as the path where the symlink should be created, and $path is being used as the target of the symlink.

  /**
   * Create a symlink from $path to $target.
   *
   * Sets @path, @target, and @reason tokens for ->succeed and ->fail.
   *
   * @param $path
   *   The path you want to perform this operation on.
   * @param $target
   *   The path you want the link to point to.
   */
  function symlink($path, $target) {
    $this->_clear_state();

    $this->tokens = array('@path' => $path, '@target' => $target);

    if (file_exists($target) && !is_link($target)) {
      $this->tokens['@reason'] = dt("A file already exists at @path");
      $this->last_status = FALSE;
    }
    elseif (is_link($target) && (readlink($target) != $path)) {
      $this->tokens['@reason'] = dt("A symlink already exists at target, but it is pointing to @link", array("@link" => readlink($target)));
      $this->last_status = FALSE;
    }
    elseif (is_link($target) && (readlink($target) == $path)) {
      $this->last_status = TRUE;
    }
    elseif (symlink($path, $target)) {
      $this->last_status = TRUE;
    }
    else {
      $this->tokens['@reason'] = dt('The symlink could not be created, an error has occured');
      $this->last_status = FALSE;
    }

    return $this;
  }

I would recommend swapping the names of both parameters (so their names match what they do, and the docs are correct), then swapping out which parameter is used throughout the code.

Like so:

  /**
   * Create a symlink from $path to $target.
   *
   * Sets @path, @target, and @reason tokens for ->succeed and ->fail.
   *
   * @param $target
   *   The path you want the link to point to.
   * @param $path
   *   The path you want to perform this operation on.
   */
  function symlink($target, $path) {
    $this->_clear_state();

    $this->tokens = array('@target' => $target, '@path' => $path);

    if (file_exists($path) && !is_link($path)) {
      $this->tokens['@reason'] = dt("A file already exists at @path");
      $this->last_status = FALSE;
    }
    elseif (is_link($path) && (readlink($path) != $target)) {
      $this->tokens['@reason'] = dt("A symlink already exists at target, but it is pointing to @link", array("@link" => readlink($path)));
      $this->last_status = FALSE;
    }
    elseif (is_link($path) && (readlink($path) == $target)) {
      $this->last_status = TRUE;
    }
    elseif (symlink($target, $path)) {
      $this->last_status = TRUE;
    }
    else {
      $this->tokens['@reason'] = dt('The symlink could not be created, an error has occured');
      $this->last_status = FALSE;
    }

    return $this;
  }

This change should not break existing provision code, since the function of the parameters was swapped, and so was the parameter order.

Comments

steven jones’s picture

Project: Hostmaster (Aegir) » Provision
Version: 6.x-1.3 » 6.x-1.x-dev
Status: Needs review » Needs work

That is confusing!

Could you provide a patch at all? http://drupal.org/patch

steven jones’s picture

Status: Needs work » Fixed

Thanks, committed the fixed docs and code.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Somehow lost the text between code blocks.

  • Commit a89dd69 on 6.x-2.x, dev-ssl-ip-allocation-refactor, dev-1205458-move_sites_out_of_platforms, 7.x-3.x, dev-subdir-multiserver, 6.x-2.x-backports, dev-helmo-3.x by Steven Jones:
    Issue #1283854 by GuyPaddock, Steven Jones: Fixed Use of parameters in...
  • Commit c0cd7d1 on 6.x-1.x, dev-drupal-8, dev-ssl-ip-allocation-refactor, dev-1205458-move_sites_out_of_platforms, 7.x-3.x, dev-subdir-multiserver, 6.x-2.x-backports, dev-helmo-3.x by Steven Jones:
    Issue #1283854 by GuyPaddock, Steven Jones: Fixed Use of parameters in...