[RFC patches 07/13] write_file: make transaction-safe