]> arthur.barton.de Git - bup.git/commit
Add atomically_replaced_file for safer output
authorNathan Bird <ecthellion@gmail.com>
Thu, 17 Jul 2014 22:27:40 +0000 (18:27 -0400)
committerRob Browning <rlb@defaultvalue.org>
Tue, 5 Aug 2014 17:02:29 +0000 (12:02 -0500)
commitc6975c8cc5a3b5286f1416dabe52725f405c34fa
tree47aca7074d491d77999d675043847572a48b130c
parent2450055507cd709da9467335f8e5ee83c724360d
Add atomically_replaced_file for safer output

Use `tempfile.mkstemp` to write files safely and then rename them
atomically to the target filename at the end. This guarantees that two
concurrent processes trying to write the same target file will result
in one process "winning" with a consistent version.

Use this to protect:
 * midx writing
 * .idx cache writing

Previously both of these processes `open(destination + '.tmp', 'w')`
which would lead to concurrent processes writing the same tmp file at
the same time.

See also https://groups.google.com/d/msg/bup-list/qdPUaXGO1cI/g8K2aFaaXz0J

Signed-off-by: Nathan Bird <ecthellion@gmail.com>
[rlb@defaultvalue.org: adjust commit message]
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/midx-cmd.py
lib/bup/client.py
lib/bup/helpers.py
lib/bup/t/thelpers.py