Closed (fixed)
Project:
Provision
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Sep 2011 at 13:55 UTC
Updated:
12 Jun 2014 at 08:41 UTC
Jump to comment: Most recent
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
Comment #1
steven jones commentedThat is confusing!
Could you provide a patch at all? http://drupal.org/patch
Comment #2
steven jones commentedThanks, committed the fixed docs and code.
Comment #3.0
(not verified) commentedSomehow lost the text between code blocks.