Patchwork [4,of,5,STABLE,pypy] test-revlog-raw: close file handles explicitly (issue5644)

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 2, 2017, 2:22 p.m.
Message ID <2c94746eb01204a1c703.1501683744@mimosa>
Download mbox | patch
Permalink /patch/22639/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 2, 2017, 2:22 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1501682318 -32400
#      Wed Aug 02 22:58:38 2017 +0900
# Branch stable
# Node ID 2c94746eb01204a1c703d555f21ebec031ed74b7
# Parent  0c342a3b5857d30c71d31e1933bcd2e4ea84be8f
test-revlog-raw: close file handles explicitly (issue5644)

Patch

diff --git a/tests/test-revlog-raw.py b/tests/test-revlog-raw.py
--- a/tests/test-revlog-raw.py
+++ b/tests/test-revlog-raw.py
@@ -144,12 +144,18 @@  def lowlevelcopy(rlog, tr, destname=b'_d
             text = None
             cachedelta = (deltaparent, rlog.revdiff(deltaparent, r))
         flags = rlog.flags(r)
-        ifh = dlog.opener(dlog.indexfile, 'a+')
-        dfh = None
-        if not dlog._inline:
-            dfh = dlog.opener(dlog.datafile, 'a+')
-        dlog._addrevision(rlog.node(r), text, tr, r, p1, p2, flags, cachedelta,
-                          ifh, dfh)
+        ifh = dfh = None
+        try:
+            ifh = dlog.opener(dlog.indexfile, 'a+')
+            if not dlog._inline:
+                dfh = dlog.opener(dlog.datafile, 'a+')
+            dlog._addrevision(rlog.node(r), text, tr, r, p1, p2, flags,
+                              cachedelta, ifh, dfh)
+        finally:
+            if dfh is not None:
+                dfh.close()
+            if ifh is not None:
+                ifh.close()
     return dlog
 
 # Utilities to generate revisions for testing