mirror of
https://git.code.sf.net/p/archivemail/code
synced 2025-02-21 14:56:51 +00:00
Complain if an mbox file being read changes sizes. (Nobody should be writing
to these files - we have locked them)
This commit is contained in:
parent
04c22934f1
commit
0cee3de4e7
1 changed files with 9 additions and 0 deletions
|
@ -229,6 +229,7 @@ class Mbox(mailbox.PortableUnixMailbox):
|
||||||
original_atime = None # last-accessed timestamp
|
original_atime = None # last-accessed timestamp
|
||||||
original_mtime = None # last-modified timestamp
|
original_mtime = None # last-modified timestamp
|
||||||
original_mode = None # file permissions to preserve
|
original_mode = None # file permissions to preserve
|
||||||
|
starting_size = None # file size of mailbox on open
|
||||||
|
|
||||||
def __init__(self, path, mode="r"):
|
def __init__(self, path, mode="r"):
|
||||||
"""Constructor for opening an existing 'mbox' mailbox.
|
"""Constructor for opening an existing 'mbox' mailbox.
|
||||||
|
@ -244,6 +245,7 @@ class Mbox(mailbox.PortableUnixMailbox):
|
||||||
self.original_atime = os.path.getatime(path)
|
self.original_atime = os.path.getatime(path)
|
||||||
self.original_mtime = os.path.getmtime(path)
|
self.original_mtime = os.path.getmtime(path)
|
||||||
self.original_mode = os.stat(path)[stat.ST_MODE]
|
self.original_mode = os.stat(path)[stat.ST_MODE]
|
||||||
|
self.starting_size = os.path.getsize(path)
|
||||||
self.mbox_file = open(path, mode)
|
self.mbox_file = open(path, mode)
|
||||||
except IOError, msg:
|
except IOError, msg:
|
||||||
unexpected_error(msg)
|
unexpected_error(msg)
|
||||||
|
@ -356,6 +358,10 @@ class Mbox(mailbox.PortableUnixMailbox):
|
||||||
blank_file = open(self.mbox_file_name, "w")
|
blank_file = open(self.mbox_file_name, "w")
|
||||||
blank_file.close()
|
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 RetainMbox(Mbox):
|
||||||
"""Class for holding messages that will be retained from the original
|
"""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")
|
vprint("finished reading messages")
|
||||||
original.exclusive_unlock()
|
original.exclusive_unlock()
|
||||||
original.close()
|
original.close()
|
||||||
|
if original.starting_size != original.get_size():
|
||||||
|
unexpected_error("the mailbox '%s' changed size during reading!" % \
|
||||||
|
mailbox_name)
|
||||||
original.reset_stat()
|
original.reset_stat()
|
||||||
if not options.dry_run:
|
if not options.dry_run:
|
||||||
if retain: retain.close()
|
if retain: retain.close()
|
||||||
|
|
Loading…
Reference in a new issue