mirror of
https://git.code.sf.net/p/archivemail/code
synced 2025-03-11 23:32:48 +00:00
mbox locking: omit dotlock if we don't have the permissions to create it
Closes: issue #855269.
This commit is contained in:
parent
11103e2de2
commit
f031573071
2 changed files with 21 additions and 2 deletions
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue