Patchwork [1,of,2,pypy-support] checklink: always close the NamedTemporaryFile

login
register
mail settings
Submitter Augie Fackler
Date Oct. 15, 2014, 8:07 p.m.
Message ID <b2d09c0ac9f97e5ce4aa.1413403656@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/6297/
State Accepted
Headers show

Comments

Augie Fackler - Oct. 15, 2014, 8:07 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1413400423 14400
#      Wed Oct 15 15:13:43 2014 -0400
# Node ID b2d09c0ac9f97e5ce4aafb9702eb1158387a8045
# Parent  582d099d5fd90f2e83837f004c2c3d246a5a71d1
checklink: always close the NamedTemporaryFile

This fixes test-patchbomb.t when using pypy with --pure.

Patch

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -156,9 +156,12 @@ 
     name = tempfile.mktemp(dir=path, prefix='hg-checklink-')
     try:
         fd = tempfile.NamedTemporaryFile(dir=path, prefix='hg-checklink-')
-        os.symlink(os.path.basename(fd.name), name)
-        os.unlink(name)
-        return True
+        try:
+            os.symlink(os.path.basename(fd.name), name)
+            os.unlink(name)
+            return True
+        finally:
+            fd.close()
     except AttributeError:
         return False
     except OSError, inst: