]> arthur.barton.de Git - bup.git/commitdiff
atomically_replaced_file: ensure error leaves original
authorRob Browning <rlb@defaultvalue.org>
Wed, 6 Aug 2014 02:01:08 +0000 (21:01 -0500)
committerRob Browning <rlb@defaultvalue.org>
Wed, 6 Aug 2014 02:16:57 +0000 (21:16 -0500)
Make sure an exception inside the body leaves the original file
content.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/t/thelpers.py

index 97438142dcf71a01ed3fd5d5dc5ded141c89fcf9..68004b72f03e69633fa765d776144a90c3e90b42 100644 (file)
@@ -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')