summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/app/lifecycle.py27
-rw-r--r--src/mailman/app/tests/test_lifecycle.py14
-rw-r--r--src/mailman/archiving/prototype.py1
3 files changed, 20 insertions, 22 deletions
diff --git a/src/mailman/app/lifecycle.py b/src/mailman/app/lifecycle.py
index c2c4047ae..676953ebe 100644
--- a/src/mailman/app/lifecycle.py
+++ b/src/mailman/app/lifecycle.py
@@ -27,6 +27,7 @@ __all__ = [
import os
+import errno
import shutil
import logging
@@ -98,27 +99,13 @@ def create_list(fqdn_listname, owners=None, style_name=None):
def remove_list(mlist):
"""Remove the list and all associated artifacts and subscriptions."""
fqdn_listname = mlist.fqdn_listname
- removeables = []
# Delete the mailing list from the database.
getUtility(IListManager).delete(mlist)
# Do the MTA-specific list deletion tasks
call_name(config.mta.incoming).delete(mlist)
- # Remove the list directory.
- removeables.append(os.path.join(config.LIST_DATA_DIR, fqdn_listname))
- # Remove any stale locks associated with the list.
- for filename in os.listdir(config.LOCK_DIR):
- fn_listname, dot, rest = filename.partition('.')
- if fn_listname == fqdn_listname:
- removeables.append(os.path.join(config.LOCK_DIR, filename))
- # Now that we know what files and directories to delete, delete them.
- for target in removeables:
- if not os.path.exists(target):
- pass
- elif os.path.islink(target):
- os.unlink(target)
- elif os.path.isdir(target):
- shutil.rmtree(target)
- elif os.path.isfile(target):
- os.unlink(target)
- else:
- log.error('Could not delete list artifact: %s', target)
+ # Remove the list directory, if it exists.
+ try:
+ shutil.rmtree(os.path.join(config.LIST_DATA_DIR, fqdn_listname))
+ except OSError as error:
+ if error.errno != errno.ENOENT:
+ raise
diff --git a/src/mailman/app/tests/test_lifecycle.py b/src/mailman/app/tests/test_lifecycle.py
index 555f4f238..0fb54f193 100644
--- a/src/mailman/app/tests/test_lifecycle.py
+++ b/src/mailman/app/tests/test_lifecycle.py
@@ -25,11 +25,14 @@ __all__ = [
]
+import os
+import shutil
import unittest
+from mailman.config import config
from mailman.interfaces.address import InvalidEmailAddressError
from mailman.interfaces.domain import BadDomainSpecificationError
-from mailman.app.lifecycle import create_list
+from mailman.app.lifecycle import create_list, remove_list
from mailman.testing.layers import ConfigLayer
@@ -48,3 +51,12 @@ class TestLifecycle(unittest.TestCase):
# Creating a list with an unregistered domain raises an exception.
self.assertRaises(BadDomainSpecificationError,
create_list, 'test@nodomain.example.org')
+
+ def test_remove_list_error(self):
+ # An error occurs while deleting the list's data directory.
+ mlist = create_list('test@example.com')
+ data_dir = os.path.join(config.LIST_DATA_DIR, mlist.fqdn_listname)
+ os.chmod(data_dir, 0)
+ self.addCleanup(shutil.rmtree, data_dir)
+ self.assertRaises(OSError, remove_list, mlist)
+ os.chmod(data_dir, 0o777)
diff --git a/src/mailman/archiving/prototype.py b/src/mailman/archiving/prototype.py
index be6603356..153c44b69 100644
--- a/src/mailman/archiving/prototype.py
+++ b/src/mailman/archiving/prototype.py
@@ -91,7 +91,6 @@ class Prototype:
mailbox = Maildir(list_dir, create=True, factory=None)
lock_file = os.path.join(
config.LOCK_DIR, '{0}-maildir.lock'.format(mlist.fqdn_listname))
-
# Lock the maildir as Maildir.add() is not threadsafe. Don't use the
# context manager because it's not an error if we can't acquire the
# archiver lock. We'll just log the problem and continue.