diff options
author | Paul Rodger <paul@paulrodger.com> | 2002-04-19 00:19:44 +0000 |
---|---|---|
committer | Paul Rodger <paul@paulrodger.com> | 2002-04-19 00:19:44 +0000 |
commit | 0cee3de4e7f815eb549335348d8cd3f263c67c84 (patch) | |
tree | cf55b5f36fdf2a033a1cec140a09be213170cdcb | |
parent | 04c22934f11b4025b0923f3bb2c48ca85c45185e (diff) | |
download | archivemail-0cee3de4e7f815eb549335348d8cd3f263c67c84.tar.gz archivemail-0cee3de4e7f815eb549335348d8cd3f263c67c84.tar.bz2 archivemail-0cee3de4e7f815eb549335348d8cd3f263c67c84.zip |
Complain if an mbox file being read changes sizes. (Nobody should be writing
to these files - we have locked them)
-rwxr-xr-x | archivemail.py | 9 |
1 files changed, 9 insertions, 0 deletions
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() |