mirror of
https://github.com/chatmail/relay.git
synced 2026-05-16 12:18:57 +00:00
expire: also expire tmpfs index files if mailbox expires
This commit is contained in:
@@ -24,7 +24,7 @@ def iter_mailboxes(basedir, maxnum):
|
||||
|
||||
for name in os_listdir_if_exists(basedir)[:maxnum]:
|
||||
if "@" in name:
|
||||
yield MailboxStat(basedir + "/" + name)
|
||||
yield MailboxStat(basedir + "/" + name, name)
|
||||
|
||||
|
||||
def get_file_entry(path):
|
||||
@@ -49,8 +49,9 @@ def os_listdir_if_exists(path):
|
||||
class MailboxStat:
|
||||
last_login = None
|
||||
|
||||
def __init__(self, basedir):
|
||||
def __init__(self, basedir, name):
|
||||
self.basedir = str(basedir)
|
||||
self.name = name
|
||||
self.messages = []
|
||||
self.extrafiles = []
|
||||
self.scandir(self.basedir)
|
||||
@@ -90,11 +91,13 @@ class Expiry:
|
||||
self.all_files = 0
|
||||
self.start = time.time()
|
||||
|
||||
def remove_mailbox(self, mboxdir):
|
||||
def remove_mailbox(self, mboxdir, name):
|
||||
if self.verbose:
|
||||
print_info(f"removing {mboxdir}")
|
||||
if not self.dry:
|
||||
shutil.rmtree(mboxdir)
|
||||
if self.config.tmpfs_index:
|
||||
shutil.rmtree("/dev/shm/" + name)
|
||||
self.del_mboxes += 1
|
||||
|
||||
def remove_file(self, path, mtime=None):
|
||||
@@ -121,7 +124,7 @@ class Expiry:
|
||||
self.all_mboxes += 1
|
||||
changed = False
|
||||
if mbox.last_login and mbox.last_login < cutoff_without_login:
|
||||
self.remove_mailbox(mbox.basedir)
|
||||
self.remove_mailbox(mbox.basedir, mbox.name)
|
||||
return
|
||||
|
||||
mboxname = os.path.basename(mbox.basedir)
|
||||
|
||||
@@ -43,20 +43,22 @@ def create_new_messages(basedir, relpaths, size=1000, days=0):
|
||||
|
||||
@pytest.fixture
|
||||
def mbox1(example_config):
|
||||
mboxdir = example_config.mailboxes_dir.joinpath("mailbox1@example.org")
|
||||
addr = "mailbox1@example.org"
|
||||
mboxdir = example_config.mailboxes_dir.joinpath(addr)
|
||||
mboxdir.mkdir()
|
||||
fill_mbox(mboxdir)
|
||||
return MailboxStat(mboxdir)
|
||||
return MailboxStat(mboxdir, addr)
|
||||
|
||||
|
||||
def test_deltachat_folder(example_config):
|
||||
"""Test old setups that might have a .DeltaChat folder where messages also need to get removed."""
|
||||
mboxdir = example_config.mailboxes_dir.joinpath("mailbox1@example.org")
|
||||
addr = "mailbox1@example.org"
|
||||
mboxdir = example_config.mailboxes_dir.joinpath(addr)
|
||||
mboxdir.mkdir()
|
||||
mbox2dir = mboxdir.joinpath(".DeltaChat")
|
||||
mbox2dir.mkdir()
|
||||
fill_mbox(mbox2dir)
|
||||
mb = MailboxStat(mboxdir)
|
||||
mb = MailboxStat(mboxdir, addr)
|
||||
assert len(mb.messages) == 2
|
||||
|
||||
|
||||
@@ -86,13 +88,13 @@ def test_stats_mailbox(mbox1):
|
||||
|
||||
create_new_messages(mbox1.basedir, ["large-extra"], size=1000)
|
||||
create_new_messages(mbox1.basedir, ["index-something"], size=3)
|
||||
mbox2 = MailboxStat(mbox1.basedir)
|
||||
mbox2 = MailboxStat(mbox1.basedir, mbox1.name)
|
||||
assert len(mbox2.extrafiles) == 5
|
||||
assert mbox2.extrafiles[0].size == 1000
|
||||
|
||||
# cope well with mailbox dirs that have no password (for whatever reason)
|
||||
Path(mbox1.basedir).joinpath("password").unlink()
|
||||
mbox3 = MailboxStat(mbox1.basedir)
|
||||
mbox3 = MailboxStat(mbox1.basedir, mbox1.name)
|
||||
assert mbox3.last_login is None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user