aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolaus Schulz <microschulz@web.de>2009-11-23 20:12:57 +0100
committerNikolaus Schulz <microschulz@web.de>2010-07-19 01:13:25 +0200
commitf031573071e693e9a976d6d37b4cc11cf81f8702 (patch)
treebdbc5851b3af03fd492d5bafe6ee7095abc8a47f
parent11103e2de2836f780adf17175f4fff189e1ebcaf (diff)
downloadarchivemail-f031573071e693e9a976d6d37b4cc11cf81f8702.tar.gz
archivemail-f031573071e693e9a976d6d37b4cc11cf81f8702.tar.bz2
archivemail-f031573071e693e9a976d6d37b4cc11cf81f8702.zip
mbox locking: omit dotlock if we don't have the permissions to create it
Closes: issue #855269.
-rwxr-xr-xarchivemail.py12
-rwxr-xr-xtest_archivemail.py11
2 files changed, 21 insertions, 2 deletions
diff --git a/archivemail.py b/archivemail.py
index 9b21ffd..5e93765 100755
--- a/archivemail.py
+++ b/archivemail.py
@@ -407,8 +407,16 @@ class Mbox(mailbox.UnixMailbox):
pid = os.getpid()
box_dir, prelock_prefix = os.path.split(self.mbox_file_name)
prelock_suffix = ".%s.%s%s" % (hostname, pid, options.lockfile_extension)
- plfd, prelock_name = tempfile.mkstemp(prelock_suffix, prelock_prefix,
- dir=box_dir)
+ try:
+ plfd, prelock_name = tempfile.mkstemp(prelock_suffix, prelock_prefix,
+ dir=box_dir)
+ except OSError, e:
+ if e.errno == errno.EACCES:
+ if not options.quiet:
+ user_warning("no write permissions: omitting dotlock for '%s'" % \
+ self.mbox_file_name)
+ return
+ raise
lock_name = self.mbox_file_name + options.lockfile_extension
try:
try:
diff --git a/test_archivemail.py b/test_archivemail.py
index 55c294f..738a5c2 100755
--- a/test_archivemail.py
+++ b/test_archivemail.py
@@ -120,6 +120,17 @@ class TestMboxDotlock(TestCaseInTempdir):
self.mbox._dotlock_unlock()
assert(not os.path.isfile(lock))
+ def testDotlockingSucceedsUponEACCES(self):
+ """A dotlock should silently be omitted upon EACCES."""
+ archivemail.options.quiet = True
+ mbox_dir = os.path.dirname(self.mbox_name)
+ os.chmod(mbox_dir, 0500)
+ try:
+ self.mbox._dotlock_lock()
+ finally:
+ os.chmod(mbox_dir, 0700)
+ archivemail.options.quiet = False
+
class TestMboxPosixLock(TestCaseInTempdir):
def setUp(self):
super(TestMboxPosixLock, self).setUp()