aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2021-05-20 15:00:31 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2021-05-20 15:00:31 -0400
commit5e1f198ef2275ca0bd2db0f264ed75ae8561b73d (patch)
tree52e9ffb094080772c173fb53f832c92cc58d333e
parentabf5f62cb35d38a4bf98f49cc77dc365544ff2ab (diff)
downloadb4-5e1f198ef2275ca0bd2db0f264ed75ae8561b73d.tar.gz
Write maildir atomically
It probably doesn't matter for b4 usage, but the maildir standard requires that files are written to tmp first and then moved into new (or hardlinked, really, then removed from tmp). Since nothing is reading the dir we're writing to, it's not as important to fully follow the standard when it comes to hardlinking, but let's at least move them into place once writing is completed. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/mbox.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/b4/mbox.py b/b4/mbox.py
index 910bac5..74e0f8e 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -126,9 +126,12 @@ def make_am(msgs, cmdargs, msgid):
pathlib.Path(d_new).mkdir(parents=True)
d_cur = os.path.join(am_filename, 'cur')
pathlib.Path(d_cur).mkdir(parents=True)
+ d_tmp = os.path.join(am_filename, 'tmp')
+ pathlib.Path(d_tmp).mkdir(parents=True)
for m_slug, msg in am_msgs:
- with open(os.path.join(d_new, f'{m_slug}.eml'), 'wb') as mfh:
+ with open(os.path.join(d_tmp, f'{m_slug}.eml'), 'wb') as mfh:
mfh.write(msg.as_bytes(policy=b4.emlpolicy))
+ os.rename(os.path.join(d_tmp, f'{m_slug}.eml'), os.path.join(d_new, f'{m_slug}.eml'))
else:
with open(am_filename, 'wb') as fh:
b4.save_git_am_mbox([x[1] for x in am_msgs], fh)