summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2011-02-12 00:03:31 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2011-02-12 00:03:31 (GMT)
commit774a66deda3a1573171c7c1ea9930ac769180604 (patch)
treefed394ab49accd1daf6963af5442e366705f5430 /Lib
parentfc14114ca936829a74556bdbdaa494bf55103bb1 (diff)
downloadcpython-774a66deda3a1573171c7c1ea9930ac769180604.zip
cpython-774a66deda3a1573171c7c1ea9930ac769180604.tar.gz
cpython-774a66deda3a1573171c7c1ea9930ac769180604.tar.bz2
Fix #11116 fix on Windows (close file before removing in MH code)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/mailbox.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 928e795..2a0d321 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -910,6 +910,7 @@ class MH(Mailbox):
new_key = max(keys) + 1
new_path = os.path.join(self._path, str(new_key))
f = _create_carefully(new_path)
+ closed = False
try:
if self._locked:
_lock_file(f)
@@ -917,6 +918,11 @@ class MH(Mailbox):
try:
self._dump_message(message, f)
except BaseException:
+ # Unlock and close so it can be deleted on Windows
+ if self._locked:
+ _unlock_file(f)
+ _sync_close(f)
+ closed = True
os.remove(new_path)
raise
if isinstance(message, MHMessage):
@@ -925,7 +931,8 @@ class MH(Mailbox):
if self._locked:
_unlock_file(f)
finally:
- _sync_close(f)
+ if not closed:
+ _sync_close(f)
return new_key
def remove(self, key):