Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
bb876b9c
Commit
bb876b9c
authored
Nov 10, 2006
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Patch #1514544 by David Watson] use fsync() to ensure data is really on disk
parent
f2d5c6d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
9 deletions
+29
-9
Lib/mailbox.py
Lib/mailbox.py
+23
-7
Misc/NEWS
Misc/NEWS
+6
-2
No files found.
Lib/mailbox.py
View file @
bb876b9c
...
...
@@ -2,6 +2,12 @@
"""Read/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes."""
# Notes for authors of new mailbox subclasses:
#
# Remember to fsync() changes to disk before closing a modified file
# or returning from a flush() method. See functions _sync_flush() and
# _sync_close().
import
sys
import
os
import
time
...
...
@@ -238,7 +244,7 @@ class Maildir(Mailbox):
try
:
self
.
_dump_message
(
message
,
tmp_file
)
finally
:
tmp_file
.
close
(
)
_sync_close
(
tmp_file
)
if
isinstance
(
message
,
MaildirMessage
):
subdir
=
message
.
get_subdir
()
suffix
=
self
.
colon
+
message
.
get_info
()
...
...
@@ -565,7 +571,8 @@ class _singlefileMailbox(Mailbox):
new_file
.
close
()
os
.
remove
(
new_file
.
name
)
raise
new_file
.
close
()
_sync_close
(
new_file
)
# self._file is about to get replaced, so no need to sync.
self
.
_file
.
close
()
try
:
os
.
rename
(
new_file
.
name
,
self
.
_path
)
...
...
@@ -599,7 +606,7 @@ class _singlefileMailbox(Mailbox):
self
.
flush
()
if
self
.
_locked
:
self
.
unlock
()
self
.
_file
.
close
()
self
.
_file
.
close
()
# Sync has been done by self.flush() above.
def
_lookup
(
self
,
key
=
None
):
"""Return (start, stop) or raise KeyError."""
...
...
@@ -789,7 +796,7 @@ class MH(Mailbox):
if
self
.
_locked
:
_unlock_file
(
f
)
finally
:
f
.
close
(
)
_sync_close
(
f
)
return
new_key
def
remove
(
self
,
key
):
...
...
@@ -836,7 +843,7 @@ class MH(Mailbox):
if
self
.
_locked
:
_unlock_file
(
f
)
finally
:
f
.
close
(
)
_sync_close
(
f
)
def
get_message
(
self
,
key
):
"""Return a Message representation or raise a KeyError."""
...
...
@@ -923,7 +930,7 @@ class MH(Mailbox):
"""Unlock the mailbox if it is locked."""
if
self
.
_locked
:
_unlock_file
(
self
.
_file
)
self
.
_file
.
close
(
)
_sync_close
(
self
.
_file
)
del
self
.
_file
self
.
_locked
=
False
...
...
@@ -1020,7 +1027,7 @@ class MH(Mailbox):
else
:
f
.
write
(
'
\
n
'
)
finally
:
f
.
close
(
)
_sync_close
(
f
)
def
pack
(
self
):
"""Re-name messages to eliminate numbering gaps. Invalidates keys."""
...
...
@@ -1874,6 +1881,15 @@ def _create_temporary(path):
socket
.
gethostname
(),
os
.
getpid
()))
def
_sync_flush
(
f
):
"""Ensure changes to file f are physically on disk."""
f
.
flush
()
os
.
fsync
(
f
.
fileno
())
def
_sync_close
(
f
):
"""Close file f, ensuring all changes are physically on disk."""
_sync_flush
(
f
)
f
.
close
()
## Start: classes from the original module (for backward compatibility).
...
...
Misc/NEWS
View file @
bb876b9c
...
...
@@ -137,8 +137,12 @@ Library
weren
't passing the message factory on to newly created Maildir/MH
objects.
- Bug #1575506: Single-file mailboxes didn'
t
re
-
lock
properly
in
their
flush
()
method
.
- Bug #1575506: mailbox.py: Single-file mailboxes didn'
t
re
-
lock
properly
in
their
flush
()
method
.
-
Patch
#
1514544
:
mailbox
.
py
:
Try
to
ensure
that
messages
/
indexes
have
been
physically
written
to
disk
after
calling
.
flush
()
or
.
close
().
(
Patch
by
David
Watson
.)
-
Bug
#
1576241
:
fix
functools
.
wraps
()
to
work
on
built
-
in
functions
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment