diff --git a/platform/backup.provision.inc b/platform/backup.provision.inc index 5ce72ab55ad10a19f3870a20d6acab145e0745c3..bd1cbfaebc5ec2578c9e2984a159f750e4de6087 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 b9243b0f4af64240161248ea1a32c1ad7243369e..4a598b65fe1f58042e918897f0d3f1bb926493e9 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 @path to @confirm"), dt("Could not change permissions @path 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 @path"), dt("Could not change ownership @path"), '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 @path"), dt("Could not change group ownership @path")); } diff --git a/provision.path.inc b/provision.path.inc index 4b3afc0f0ff56d20c8851280d0cd271e8bea5142..e6bbafe22b3b44e0d6ff1fffe044691eb01ace0c 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; + } +}