diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-09-18 12:36:36 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-09-18 12:36:36 (GMT) |
commit | cf6d0e77ea48e2e3f31c08782abb6e9be39012c8 (patch) | |
tree | 6e7a0214e71787741699c4524ab28d03256b04a1 /Lib/mailbox.py | |
parent | b7c1a5dcadfd13cb0afe92ab7e9cb4398259107f (diff) | |
parent | 41a22f1a778b87dee7b848c110a82e0a5b85208f (diff) | |
download | cpython-cf6d0e77ea48e2e3f31c08782abb6e9be39012c8.zip cpython-cf6d0e77ea48e2e3f31c08782abb6e9be39012c8.tar.gz cpython-cf6d0e77ea48e2e3f31c08782abb6e9be39012c8.tar.bz2 |
Merge #19037: adjust file times *before* moving maildir files into place.
Diffstat (limited to 'Lib/mailbox.py')
-rw-r--r-- | Lib/mailbox.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 2049516..5f591bc 100644 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -308,6 +308,12 @@ class Maildir(Mailbox): suffix = '' uniq = os.path.basename(tmp_file.name).split(self.colon)[0] dest = os.path.join(self._path, subdir, uniq + suffix) + if isinstance(message, MaildirMessage): + os.utime(tmp_file.name, + (os.path.getatime(tmp_file.name), message.get_date())) + # No file modification should be done after the file is moved to its + # final position in order to prevent race conditions with changes + # from other programs try: if hasattr(os, 'link'): os.link(tmp_file.name, dest) @@ -321,8 +327,6 @@ class Maildir(Mailbox): % dest) else: raise - if isinstance(message, MaildirMessage): - os.utime(dest, (os.path.getatime(dest), message.get_date())) return uniq def remove(self, key): @@ -354,11 +358,15 @@ class Maildir(Mailbox): else: suffix = '' self.discard(key) + tmp_path = os.path.join(self._path, temp_subpath) new_path = os.path.join(self._path, subdir, key + suffix) - os.rename(os.path.join(self._path, temp_subpath), new_path) if isinstance(message, MaildirMessage): - os.utime(new_path, (os.path.getatime(new_path), - message.get_date())) + os.utime(tmp_path, + (os.path.getatime(tmp_path), message.get_date())) + # No file modification should be done after the file is moved to its + # final position in order to prevent race conditions with changes + # from other programs + os.rename(tmp_path, new_path) def get_message(self, key): """Return a Message representation or raise a KeyError.""" |