mirror of
https://git.code.sf.net/p/archivemail/code
synced 2024-12-22 15:56:27 +00:00
Fixed a bug where if you ran: 'archivemail.py foo/mbox' it would create
the archive file in the current directory instead of the directory 'foo'.
This commit is contained in:
parent
81c82ddaf5
commit
4ac9643118
1 changed files with 42 additions and 17 deletions
|
@ -146,7 +146,7 @@ class Options:
|
||||||
lockfile_attempts = 5
|
lockfile_attempts = 5
|
||||||
lockfile_extension = ".lock"
|
lockfile_extension = ".lock"
|
||||||
lockfile_sleep = 1
|
lockfile_sleep = 1
|
||||||
output_dir = os.curdir
|
output_dir = None
|
||||||
quiet = 0
|
quiet = 0
|
||||||
script_name = os.path.basename(sys.argv[0])
|
script_name = os.path.basename(sys.argv[0])
|
||||||
verbose = 0
|
verbose = 0
|
||||||
|
@ -218,6 +218,7 @@ class Options:
|
||||||
|
|
||||||
def sanity_check(self):
|
def sanity_check(self):
|
||||||
"""Complain bitterly about our options now rather than later"""
|
"""Complain bitterly about our options now rather than later"""
|
||||||
|
if self.output_dir:
|
||||||
if not os.path.isdir(self.output_dir):
|
if not os.path.isdir(self.output_dir):
|
||||||
user_error("output directory does not exist: '%s'" % \
|
user_error("output directory does not exist: '%s'" % \
|
||||||
self.output_dir)
|
self.output_dir)
|
||||||
|
@ -225,8 +226,8 @@ class Options:
|
||||||
user_error("no write permission on output directory: '%s'" % \
|
user_error("no write permission on output directory: '%s'" % \
|
||||||
self.output_dir)
|
self.output_dir)
|
||||||
if is_world_writable(self.output_dir):
|
if is_world_writable(self.output_dir):
|
||||||
unexpected_error(("output directory is world-writable: '%s' " + \
|
unexpected_error(("output directory is world-writable: " + \
|
||||||
"-- I feel nervous!") % self.output_dir)
|
"%s -- I feel nervous!") % self.output_dir)
|
||||||
if (self.days_old_max < 1):
|
if (self.days_old_max < 1):
|
||||||
user_error("argument to -d must be greater than zero")
|
user_error("argument to -d must be greater than zero")
|
||||||
if (self.days_old_max >= 10000):
|
if (self.days_old_max >= 10000):
|
||||||
|
@ -519,8 +520,6 @@ Website: http://archivemail.sourceforge.net/ """ % \
|
||||||
|
|
||||||
_options.sanity_check()
|
_options.sanity_check()
|
||||||
os.umask(077) # saves setting permissions on mailboxes/tempfiles
|
os.umask(077) # saves setting permissions on mailboxes/tempfiles
|
||||||
tempfile.tempdir = _options.output_dir
|
|
||||||
assert(tempfile.tempdir)
|
|
||||||
|
|
||||||
# Make sure we clean up nicely - we don't want to leave stale procmail
|
# 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
|
# lockfiles about if something bad happens to us. This is quite
|
||||||
|
@ -671,13 +670,16 @@ def archive(mailbox_name):
|
||||||
"""
|
"""
|
||||||
assert(mailbox_name)
|
assert(mailbox_name)
|
||||||
|
|
||||||
vprint("set tempfile directory to '%s'" % tempfile.tempdir)
|
|
||||||
|
|
||||||
final_archive_name = mailbox_name + _options.archive_suffix
|
final_archive_name = mailbox_name + _options.archive_suffix
|
||||||
|
if _options.output_dir:
|
||||||
final_archive_name = os.path.join(_options.output_dir,
|
final_archive_name = os.path.join(_options.output_dir,
|
||||||
os.path.basename(final_archive_name))
|
os.path.basename(final_archive_name))
|
||||||
vprint("archiving '%s' to '%s' ..." % (mailbox_name, final_archive_name))
|
vprint("archiving '%s' to '%s' ..." % (mailbox_name, final_archive_name))
|
||||||
|
|
||||||
|
tempfile.tempdir = choose_temp_dir(mailbox_name)
|
||||||
|
assert(tempfile.tempdir)
|
||||||
|
vprint("set tempfile directory to '%s'" % tempfile.tempdir)
|
||||||
|
|
||||||
# check to see if we are running as root -- if so, change our effective
|
# check to see if we are running as root -- if so, change our effective
|
||||||
# userid and groupid to that of the original mailbox
|
# userid and groupid to that of the original mailbox
|
||||||
if (os.getuid() == 0) and os.path.exists(mailbox_name):
|
if (os.getuid() == 0) and os.path.exists(mailbox_name):
|
||||||
|
@ -843,6 +845,29 @@ def _archive_dir(mailbox_name, final_archive_name, type):
|
||||||
|
|
||||||
############### misc functions ###############
|
############### misc functions ###############
|
||||||
|
|
||||||
|
|
||||||
|
def choose_temp_dir(mailbox_name):
|
||||||
|
"""Return a suitable temporary directory to use for a given mailbox name"""
|
||||||
|
assert(mailbox_name)
|
||||||
|
mailbox_dirname = os.path.dirname(mailbox_name)
|
||||||
|
temp_dir = None
|
||||||
|
|
||||||
|
if _options.output_dir:
|
||||||
|
temp_dir = _options.output_dir
|
||||||
|
elif mailbox_dirname:
|
||||||
|
temp_dir = mailbox_dirname
|
||||||
|
else:
|
||||||
|
temp_dir = os.curdir
|
||||||
|
assert(temp_dir)
|
||||||
|
if is_world_writable(temp_dir):
|
||||||
|
unexpected_error(("temporary directory is world-writable: " + \
|
||||||
|
"%s -- I feel nervous!") % temp_dir)
|
||||||
|
if not os.access(temp_dir, os.W_OK):
|
||||||
|
user_error("no write permission on temporary directory: '%s'" % \
|
||||||
|
temp_dir)
|
||||||
|
return temp_dir
|
||||||
|
|
||||||
|
|
||||||
def clean_up():
|
def clean_up():
|
||||||
"""Delete stale files -- to be registered with atexit.register()"""
|
"""Delete stale files -- to be registered with atexit.register()"""
|
||||||
vprint("cleaning up ...")
|
vprint("cleaning up ...")
|
||||||
|
|
Loading…
Reference in a new issue