summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Araña Cruz2010-10-04 14:49:15 +0000
committerJonathan Araña Cruz2010-10-04 14:49:15 +0000
commit16a4e2b3cf0420a7dce7d3ed79f6701bdd97e095 (patch)
treee5c55c4fd0dd4364f13cdcc574141ba9d316ddc8
parente7e62b636719a383e6bd455a223b532ad68af87b (diff)
Force to use a location for backups outside the drupal root.
-rw-r--r--commands/pm/pm.drush.inc31
-rw-r--r--commands/pm/version_control/backup.inc17
2 files changed, 29 insertions, 19 deletions
diff --git a/commands/pm/pm.drush.inc b/commands/pm/pm.drush.inc
index fd2346e..bf289a9 100644
--- a/commands/pm/pm.drush.inc
+++ b/commands/pm/pm.drush.inc
@@ -97,7 +97,6 @@ function pm_drush_command() {
);
$update_options = array(
'--lock' => 'Add a persistent lock to remove the specified projects from consideration during updates. Locks may be removed with the --unlock parameter, or overridden by specifically naming the module as a parameter to pm-update or pm-updatecode. The lock does not affect pm-download.',
- '--backup-dir' => 'Specify a directory to backup packages into, defaults to a backup directory within your Drupal root.',
);
$update_suboptions = array(
'--lock' => array(
@@ -955,6 +954,16 @@ function drush_pm_post_pm_update() {
}
/**
+ * Validate callback for updatecode command. Abort if 'backup' folder exists.
+ */
+function drush_pm_updatecode_validate() {
+ $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
+ if (is_dir($drupal_root . DIRECTORY_SEPARATOR . 'backup')) {
+ return drush_set_error('DRUSH_PM_BACKUP_DIR_FORBIDDEN', dt('It\'s a security risk to have a backup folder in your Drupal root. You must move it elsewhere before proceeding.'));
+ }
+}
+
+/**
* Post-command callback for updatecode. Notify about any pending DB updates.
*/
function drush_pm_post_pm_updatecode() {
@@ -1197,6 +1206,16 @@ function pm_drush_engine_package_handler() {
*/
function pm_drush_engine_version_control() {
return array(
+ 'backup' => array(
+ 'options' => array(
+ '--version-control=backup' => 'Default engine. Backup all project files before updates.',
+ ),
+ 'sub-options' => array(
+ '--version-control=backup' => array(
+ '--backup-dir' => 'Specify a directory to backup packages into. Defaults to .drush-backups within the home directory of the user running the command. It is forbidden to specify a directory inside your drupal root.',
+ ),
+ ),
+ ),
'svn' => array(
'signature' => 'svn info %s',
'options' => array(
@@ -1218,16 +1237,6 @@ function pm_drush_engine_version_control() {
'drush [command] cck --svncommitparams=\"--username joe\"' => 'Commit changes as the user \'joe\' (Quotes are required).'
),
),
- 'backup' => array(
- 'options' => array(
- '--version-control=backup' => 'Backup all project files before updates.',
- ),
- 'sub-options' => array(
- '--version-control=backup' => array(
- '--backup-dir' => 'Backup destination directory. Defaults to a "/backup" subdirectory inside your Drupal root.',
- ),
- ),
- ),
'bzr' => array(
'signature' => 'bzr root %s',
'options' => array(
diff --git a/commands/pm/version_control/backup.inc b/commands/pm/version_control/backup.inc
index db7f4a3..02b2e4a 100644
--- a/commands/pm/version_control/backup.inc
+++ b/commands/pm/version_control/backup.inc
@@ -16,14 +16,15 @@ class drush_pm_version_control_backup implements drush_pm_version_control {
// Save the date to be used in the backup directory's path name.
$date = date('YmdHis', $_SERVER['REQUEST_TIME']);
- $backup_dir = drush_get_option('backup-dir', $drupal_root . '/backup');
- $backup_dir = rtrim($backup_dir, '/');
- @drush_op('mkdir', $backup_dir, 0777);
- $backup_dir .= '/modules';
- @drush_op('mkdir', $backup_dir, 0777);
- $backup_dir .= "/$date";
- @drush_op('mkdir', $backup_dir, 0777);
- $backup_target = $backup_dir . '/'. $project['name'];
+ $backup_dir = drush_get_option('backup-dir', $_SERVER['HOME'] . DIRECTORY_SEPARATOR . '.drush-backups');
+ if (strpos($backup_dir, $drupal_root) === 0) {
+ return drush_set_error('DRUSH_PM_BACKUP_FAILED', dt('It\'s not allowed to store backups inside the Drupal root directory.'));
+ }
+ $backup_dir = rtrim($backup_dir, DIRECTORY_SEPARATOR);
+ $backup_dir .= DIRECTORY_SEPARATOR . $date . DIRECTORY_SEPARATOR . 'modules';
+ drush_mkdir($backup_dir);
+
+ $backup_target = $backup_dir . DIRECTORY_SEPARATOR . $project['name'];
// Save for rollback or notifications.
$project['backup_target'] = $backup_target;
if (!drush_op('rename', $project['full_project_path'], $backup_target)) {