From 0cee3de4e7f815eb549335348d8cd3f263c67c84 Mon Sep 17 00:00:00 2001 From: Paul Rodger Date: Fri, 19 Apr 2002 00:19:44 +0000 Subject: Complain if an mbox file being read changes sizes. (Nobody should be writing to these files - we have locked them) --- archivemail.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/archivemail.py b/archivemail.py index cd874b9..f444735 100755 --- a/archivemail.py +++ b/archivemail.py @@ -229,6 +229,7 @@ class Mbox(mailbox.PortableUnixMailbox): original_atime = None # last-accessed timestamp original_mtime = None # last-modified timestamp original_mode = None # file permissions to preserve + starting_size = None # file size of mailbox on open def __init__(self, path, mode="r"): """Constructor for opening an existing 'mbox' mailbox. @@ -244,6 +245,7 @@ class Mbox(mailbox.PortableUnixMailbox): self.original_atime = os.path.getatime(path) self.original_mtime = os.path.getmtime(path) self.original_mode = os.stat(path)[stat.ST_MODE] + self.starting_size = os.path.getsize(path) self.mbox_file = open(path, mode) except IOError, msg: unexpected_error(msg) @@ -356,6 +358,10 @@ class Mbox(mailbox.PortableUnixMailbox): blank_file = open(self.mbox_file_name, "w") blank_file.close() + def get_size(self): + """Return the current size of the mbox file""" + return os.path.getsize(self.mbox_file_name) + class RetainMbox(Mbox): """Class for holding messages that will be retained from the original @@ -891,6 +897,9 @@ def _archive_mbox(mailbox_name, final_archive_name): vprint("finished reading messages") original.exclusive_unlock() original.close() + if original.starting_size != original.get_size(): + unexpected_error("the mailbox '%s' changed size during reading!" % \ + mailbox_name) original.reset_stat() if not options.dry_run: if retain: retain.close() -- cgit v1.2.3