summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Rossouw2009-06-30 01:28:53 (GMT)
committeradrian2009-06-30 01:28:53 (GMT)
commit3ebd37aa0306a85485505a860c493e882c2ff2b9 (patch)
treeb207d80ae03e632a23d922b0ff34ccb0fa960987
parent6529e1952d69f85192d181ca4039e9ff13f9ab22 (diff)
Added chmod_recursive, chown_recursive and chgrp_recursive to provision_path, and also added -p to the tarball creation and extraction, to preserve permissions.
-rw-r--r--platform/backup.provision.inc2
-rw-r--r--platform/provision_drupal.drush.inc6
-rw-r--r--provision.path.inc83
3 files changed, 78 insertions, 13 deletions
diff --git a/platform/backup.provision.inc b/platform/backup.provision.inc
index 5ce72ab..bd1cbfa 100644
--- a/platform/backup.provision.inc
+++ b/platform/backup.provision.inc
@@ -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"));
diff --git a/platform/provision_drupal.drush.inc b/platform/provision_drupal.drush.inc
index b9243b0..4a598b6 100644
--- a/platform/provision_drupal.drush.inc
+++ b/platform/provision_drupal.drush.inc
@@ -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>"));
}
diff --git a/provision.path.inc b/provision.path.inc
index 4b3afc0..e6bbafe 100644
--- a/provision.path.inc
+++ b/provision.path.inc
@@ -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;
+ }
+}