Commit 59c7ae5b authored by Barry Warsaw's avatar Barry Warsaw

- Clean up and simplify remove_list()

- Boost test coverage of to 100%
parent 11d3120d
......@@ -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.
# Do the MTA-specific list deletion tasks
# 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):
elif os.path.islink(target):
elif os.path.isdir(target):
elif os.path.isfile(target):
log.error('Could not delete list artifact: %s', target)
# Remove the list directory, if it exists.
shutil.rmtree(os.path.join(config.LIST_DATA_DIR, fqdn_listname))
except OSError as error:
if error.errno != errno.ENOENT:
......@@ -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 import create_list
from 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.
create_list, '[email protected]')
def test_remove_list_error(self):
# An error occurs while deleting the list's data directory.
mlist = create_list('[email protected]')
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)
......@@ -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.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment