1
0
Fork 0
mirror of https://git.code.sf.net/p/archivemail/code synced 2024-12-23 08:14:58 +00:00

Don't run clean_up() by means of atexit, but use a plain finally clause in the

main archive() function.  This is simpler, and it works better with the
testsuite calling archive() directly, where the atexit handler isn't triggered.
This commit is contained in:
Nikolaus Schulz 2006-10-29 03:10:45 +00:00
parent 2dbd3c1940
commit 99cfab1f4e

View file

@ -48,11 +48,10 @@ def check_python_version():
print too_old_error
sys.exit(1)
# define & run this early because 'atexit' requires Python >= 2.0
# define & run this early
# (IMAP over SSL requires Python >= 2.3)
check_python_version()
import atexit
import fcntl
import getopt
import gzip
@ -1076,8 +1075,9 @@ def archive(mailbox_name):
vprint("changing effective user id to: %d" % mailbox_user)
os.seteuid(mailbox_user)
# create a temporary directory for us to work in securely
old_temp_dir = tempfile.tempdir
try:
# create a temporary directory for us to work in securely
tempfile.tempdir = None
new_temp_dir = tempfile.mkdtemp('archivemail')
assert(new_temp_dir)
@ -1109,7 +1109,10 @@ def archive(mailbox_name):
# remove our special temp directory - hopefully empty
os.rmdir(new_temp_dir)
_stale.temp_dir = None
finally:
tempfile.tempdir = old_temp_dir
clean_up()
# if we are running as root, revert the seteuid()/setegid() above
if (os.getuid() == 0):
@ -1117,7 +1120,6 @@ def archive(mailbox_name):
os.setegid(former_gid)
os.seteuid(0)
def _archive_mbox(mailbox_name, final_archive_name):
"""Archive a 'mbox' style mailbox - used by archive_mailbox()
@ -1342,7 +1344,6 @@ def set_signal_handlers():
# Make sure we clean up nicely - we don't want to leave stale procmail
# lockfiles about if something bad happens to us. This is quite
# important, even though procmail will delete stale files after a while.
atexit.register(clean_up) # delete stale files on exceptions/normal exit
signal.signal(signal.SIGHUP, clean_up_signal) # signal 1
# SIGINT (signal 2) is handled as a python exception
signal.signal(signal.SIGQUIT, clean_up_signal) # signal 3
@ -1350,7 +1351,7 @@ def set_signal_handlers():
def clean_up():
"""Delete stale files -- to be registered with atexit.register()"""
"""Delete stale files"""
vprint("cleaning up ...")
_stale.clean()