Commit 3ebd37aa authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

Added chmod_recursive, chown_recursive and chgrp_recursive to provision_path,...

Added chmod_recursive, chown_recursive and chgrp_recursive to provision_path, and also added -p to the tarball creation and extraction, to preserve permissions.
parent 6529e195
......@@ -50,7 +50,7 @@ function drush_provision_drupal_provision_backup($url) {
$backup_file = drush_get_option('backup_file');
// Adds the site directory into the backup file
drush_log(dt("Adding sites directory to !backup_file", array('!backup_file' => $backup_file)), 'backup');
$result = provision_shell_exec("tar -C %s -r -f %s .", drush_get_option('sites_path') . "/$url", $backup_file);
$result = provision_shell_exec("tar -C %s -p -r -f %s .", drush_get_option('sites_path') . "/$url", $backup_file);
if (!$result && !drush_get_option('force', false)) {
drush_set_error('PROVISION_BACKUP_FAILED', dt("Could not back up sites directory for drupal"));
......
......@@ -240,17 +240,17 @@ function _provision_drupal_create_directories($url, $profile = NULL) {
'DRUSH_PERM_ERROR');
}
provision_path("chmod", $path, $perm,
provision_path("chmod_recursive", $path, $perm,
dt("Changed permissions of <code>@path</code> to @confirm"),
dt("Could not change permissions <code>@path</code> to @confirm"),
'DRUSH_PERM_ERROR');
}
foreach ($grps as $path) {
provision_path("chown", $path, drush_get_option('script_user'),
provision_path("chown_recursive", $path, drush_get_option('script_user'),
dt("Changed ownership of <code>@path</code>"),
dt("Could not change ownership <code>@path</code>"),
'DRUSH_PERM_ERROR' );
provision_path("chgrp", $path, drush_get_option('web_group'),
provision_path("chgrp_recursive", $path, drush_get_option('web_group'),
dt("Changed group ownership of <code>@path</code>"),
dt("Could not change group ownership <code>@path</code>"));
}
......
......@@ -161,19 +161,23 @@ function provision_path_unlink($path) {
* This is where the more complex file operations start
*/
function provision_path_chmod($path, &$perms, &$reason) {
if (!@chmod($path, $perms)) {
function provision_path_chmod($path, &$perms, &$reason, $recursive = FALSE) {
$func = ($recursive) ? '_provision_chmod_recursive' : 'chmod';
if (!@$func($path, $perms)) {
$reason = dt('chmod to @perm failed on @path', array('@perm' => sprintf('%o', $perms), '@path' => $path));
return false;
}
clearstatcache(); // this needs to be called, otherwise we get the old info
$value = substr(sprintf('%o', fileperms($path)), -4);
$perms = sprintf('%o', $perms);
return $value;
}
function provision_path_chown($path, &$owner, &$reason) {
function provision_path_chown($path, &$owner, &$reason, $recursive = FALSE) {
$func = ($recursive) ? '_provision_chown_recursive' : 'chown';
if ($owner = provision_posix_username($owner)) {
if (!chown($path, $owner)) {
if (!$func($path, $owner)) {
$reason = dt("chown to @owner failed on @path", array('@owner' => $owner, '@path' => $path)) ;
}
}
......@@ -185,10 +189,11 @@ function provision_path_chown($path, &$owner, &$reason) {
return provision_posix_username(fileowner($path));
}
function provision_path_chgrp($path, &$gid, &$reason) {
function provision_path_chgrp($path, &$gid, &$reason, $recursive = FALSE) {
$func = ($recursive) ? '_provision_chgrp_recursive' : 'chgrp';
if ($group = provision_posix_groupname($gid)) {
if (provision_user_in_group(drush_get_option('script_user'), $gid)) {
if (chgrp($path, $group)) {
if ($func($path, $group)) {
return $group;
}
else {
......@@ -199,7 +204,7 @@ function provision_path_chgrp($path, &$gid, &$reason) {
$reason = dt("@user is not in @group group", array("@user" => drush_get_option('script_user'), "@group" => $group));
}
}
elseif (!@chgrp($path, $gid)) { # try to change the group anyways
elseif (!@$func($path, $gid)) { # try to change the group anyways
$reason = dt("the group does not exist");
}
......@@ -207,6 +212,20 @@ function provision_path_chgrp($path, &$gid, &$reason) {
return provision_posix_groupname(filegroup($path));
}
function provision_path_chmod_recursive($path, &$perms, &$reason) {
return provision_path_chmod($path, $perms, $reason, TRUE);
}
function provision_path_chown_recursive($path, &$owner, &$reason) {
return provision_path_chown($path, $owner, $reason, TRUE);
}
function provision_path_chgrp_recursive($path, &$gid, &$reason) {
return provision_path_chgrp($path, $gid, $reason, TRUE);
}
function provision_path_switch_paths($path1, &$path2, &$reason) {
//TODO : Add error reasons.
$temp = $path1 .'.tmp';
......@@ -234,8 +253,8 @@ function provision_path_extract($path, &$target, &$reason) {
if (file_exists($path) && is_readable($path)) {
if (is_writeable(dirname($target)) && !file_exists($target) && !is_dir($target)) {
mkdir($target);
provision_shell_exec("tar -zxf %s -C %s", $path, $target);
drush_log(sprintf("Running: tar -zxf %s -C %s", $path, $target));
provision_shell_exec("tar -zpxf %s -C %s", $path, $target);
drush_log(sprintf("Running: tar -zpxf %s -C %s", $path, $target));
if (is_writeable(dirname($target)) && is_readable(dirname($target)) && is_dir($target)) {
$target = TRUE;
return TRUE;
......@@ -333,3 +352,49 @@ function _provision_mkdir_recursive($path, $mode) {
is_dir(dirname($path)) || _provision_mkdir_recursive(dirname($path), $mode);
return is_dir($path) || mkdir($path, $mode);
}
/**
* Chmod a directory recursively
*/
function _provision_chmod_recursive($path, $filemode) {
if ( !is_dir($path) ) {
return chmod($path, $filemode);
}
else {
$output = 0;
$cmd = sprintf("chmod -R %o %s", $filemode, $path);
system($cmd, $output);
return !$output;
}
}
/**
* Chown a directory recursively
*/
function _provision_chown_recursive($path, $owner) {
if ( !is_dir($path) ) {
return chown($path, $owner);
}
else {
$output = 0;
$cmd = sprintf("chown -R %s %s", $owner, $path);
system($cmd, $output);
return !$output;
}
}
/**
* Chgrp a directory recursively
*/
function _provision_chgrp_recursive($path, $owner) {
if ( !is_dir($path) ) {
return chgrp($path, $owner);
}
else {
$output = 0;
$cmd = sprintf("chgrp -R %s %s", $owner, $path);
system($cmd, $output);
return !$output;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment