From 84dd6f26e0a426fe655b37871c1ab907b99be0b6 Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Tue, 16 Feb 2016 12:04:52 +0000 Subject: [PATCH] Added fixed nested deleted homes problem --- orchestra/contrib/mailboxes/backends.py | 14 +++++++++++++- orchestra/contrib/systemusers/backends.py | 10 +++++++++- orchestra/contrib/webapps/backends/__init__.py | 10 +++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/orchestra/contrib/mailboxes/backends.py b/orchestra/contrib/mailboxes/backends.py index 26dca795..24e2cfb0 100644 --- a/orchestra/contrib/mailboxes/backends.py +++ b/orchestra/contrib/mailboxes/backends.py @@ -110,7 +110,18 @@ class UNIXUserMaildirBackend(SieveFilteringMixin, ServiceController): def delete(self, mailbox): context = self.get_context(mailbox) - self.append('mv %(home)s %(home)s.deleted || exit_code=$?' % context) + if context['deleted_home']: + self.append(textwrap.dedent("""\ + # Move home into MAILBOXES_MOVE_ON_DELETE_PATH, nesting if exists. + deleted_home="%(deleted_home)s" + while [[ -e $deleted_home ]]; do + deleted_home="${deleted_home}/$(basename ${deleted_home})" + done + mv %(home)s $deleted_home || exit_code=$? + """) % context + ) + else: + self.append("rm -fr %(base_home)s" % context) self.append(textwrap.dedent(""" nohup bash -c '{ sleep 2 && killall -u %(user)s -s KILL; }' &> /dev/null & killall -u %(user)s || true @@ -134,6 +145,7 @@ class UNIXUserMaildirBackend(SieveFilteringMixin, ServiceController): 'initial_shell': self.SHELL, 'banner': self.get_banner(), } + context['deleted_home'] = settings.MAILBOXES_MOVE_ON_DELETE_PATH % context return context diff --git a/orchestra/contrib/systemusers/backends.py b/orchestra/contrib/systemusers/backends.py index 734f278c..2ba7a3d7 100644 --- a/orchestra/contrib/systemusers/backends.py +++ b/orchestra/contrib/systemusers/backends.py @@ -104,7 +104,15 @@ class UNIXUserBackend(ServiceController): """) % context ) if context['deleted_home']: - self.append("mv %(base_home)s %(deleted_home)s || exit_code=$?" % context) + self.append(textwrap.dedent("""\ + # Move home into SYSTEMUSERS_MOVE_ON_DELETE_PATH, nesting if exists. + deleted_home="%(deleted_home)s" + while [[ -e $deleted_home ]]; do + deleted_home="${deleted_home}/$(basename ${deleted_home})" + done + mv %(base_home)s $deleted_home || exit_code=$? + """) % context + ) else: self.append("rm -fr %(base_home)s" % context) diff --git a/orchestra/contrib/webapps/backends/__init__.py b/orchestra/contrib/webapps/backends/__init__.py index ecc5298a..77b8ac4d 100644 --- a/orchestra/contrib/webapps/backends/__init__.py +++ b/orchestra/contrib/webapps/backends/__init__.py @@ -42,7 +42,15 @@ class WebAppServiceMixin(object): def delete_webapp_dir(self, context): if context['deleted_app_path']: - self.append("mv %(app_path)s %(deleted_app_path)s || exit_code=$?" % context) + self.append(textwrap.dedent("""\ + # Move app into WEBAPPS_MOVE_ON_DELETE_PATH, nesting if exists. + deleted_app_path="%(deleted_app_path)s" + while [[ -e $deleted_app_path ]]; do + deleted_app_path="${deleted_app_path}/$(basename ${deleted_app_path})" + done + mv %(app_path)s $deleted_app_path || exit_code=$? + """) % context + ) else: self.append("rm -fr %(app_path)s" % context)