From: Rob Browning Date: Wed, 6 Aug 2014 02:01:08 +0000 (-0500) Subject: atomically_replaced_file: ensure error leaves original X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=98b23e7254bc3f63671f0cfd63aadbc38f2e4624;p=packages%2Fb%2Fbup.git atomically_replaced_file: ensure error leaves original Make sure an exception inside the body leaves the original file content. Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/lib/bup/t/thelpers.py b/lib/bup/t/thelpers.py index 9743814..68004b7 100644 --- a/lib/bup/t/thelpers.py +++ b/lib/bup/t/thelpers.py @@ -162,6 +162,15 @@ def test_atomically_replaced_file(): f = open(target_file, 'r') WVPASSEQ(f.read(), 'asdf') + try: + with atomically_replaced_file(target_file, mode='w') as f: + f.write('wxyz') + raise Exception() + except: + pass + with open(target_file) as f: + WVPASSEQ(f.read(), 'asdf') + with atomically_replaced_file(target_file, mode='wb') as f: f.write(os.urandom(20)) WVPASSEQ(f.mode, 'wb')