summaryrefslogtreecommitdiffstats
path: root/Lib/mailbox.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/mailbox.py')
-rwxr-xr-xLib/mailbox.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index bb115e1..b72128b 100755
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -15,7 +15,10 @@ import email.Generator
import rfc822
import StringIO
try:
- import fnctl
+ if sys.platform == 'os2emx':
+ # OS/2 EMX fcntl() not adequate
+ raise ImportError
+ import fcntl
except ImportError:
fcntl = None
@@ -565,7 +568,8 @@ class _singlefileMailbox(Mailbox):
try:
os.rename(new_file.name, self._path)
except OSError, e:
- if e.errno == errno.EEXIST:
+ if e.errno == errno.EEXIST or \
+ (os.name == 'os2' and e.errno == errno.EACCES):
os.remove(self._path)
os.rename(new_file.name, self._path)
else:
@@ -1030,6 +1034,9 @@ class MH(Mailbox):
if hasattr(os, 'link'):
os.link(os.path.join(self._path, str(key)),
os.path.join(self._path, str(prev + 1)))
+ if sys.platform == 'os2emx':
+ # cannot unlink an open file on OS/2
+ f.close()
os.unlink(os.path.join(self._path, str(key)))
else:
f.close()
@@ -1798,26 +1805,18 @@ class _PartialFile(_ProxyFile):
def _lock_file(f, dotlock=True):
- """Lock file f using lockf, flock, and dot locking."""
+ """Lock file f using lockf and dot locking."""
dotlock_done = False
try:
if fcntl:
try:
fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError, e:
- if e.errno == errno.EAGAIN:
+ if e.errno in (errno.EAGAIN, errno.EACCES):
raise ExternalClashError('lockf: lock unavailable: %s' %
f.name)
else:
raise
- try:
- fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
- except IOError, e:
- if e.errno == errno.EWOULDBLOCK:
- raise ExternalClashError('flock: lock unavailable: %s' %
- f.name)
- else:
- raise
if dotlock:
try:
pre_lock = _create_temporary(f.name + '.lock')
@@ -1836,7 +1835,8 @@ def _lock_file(f, dotlock=True):
os.rename(pre_lock.name, f.name + '.lock')
dotlock_done = True
except OSError, e:
- if e.errno == errno.EEXIST:
+ if e.errno == errno.EEXIST or \
+ (os.name == 'os2' and e.errno == errno.EACCES):
os.remove(pre_lock.name)
raise ExternalClashError('dot lock unavailable: %s' %
f.name)
@@ -1845,16 +1845,14 @@ def _lock_file(f, dotlock=True):
except:
if fcntl:
fcntl.lockf(f, fcntl.LOCK_UN)
- fcntl.flock(f, fcntl.LOCK_UN)
if dotlock_done:
os.remove(f.name + '.lock')
raise
def _unlock_file(f):
- """Unlock file f using lockf, flock, and dot locking."""
+ """Unlock file f using lockf and dot locking."""
if fcntl:
fcntl.lockf(f, fcntl.LOCK_UN)
- fcntl.flock(f, fcntl.LOCK_UN)
if os.path.exists(f.name + '.lock'):
os.remove(f.name + '.lock')