changeset 3057:d16b93f4a6ca

unlink temporary patch files even when an exception is raised
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Tue, 05 Sep 2006 01:11:14 +0200
parents 6848528f7ebd
children 11e3396e3a2b
files mercurial/patch.py
diffstat 1 files changed, 21 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Wed Aug 30 13:42:57 2006 -0700
+++ b/mercurial/patch.py	Tue Sep 05 01:11:14 2006 +0200
@@ -227,14 +227,14 @@
     """apply the patch <patchname> to the working directory.
     a list of patched files is returned"""
 
-    (dopatch, gitpatches) = readgitpatch(patchname)
+    # helper function
+    def __patch(patchname):
+        """patch and updates the files and fuzz variables"""
+        files = {}
+        fuzz = False
 
-    files = {}
-    fuzz = False
-    if dopatch:
-        if dopatch == 'filter':
-            patchname = dogitpatch(patchname, gitpatches, cwd=cwd)
-        patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
+        patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''),
+                                    'patch')
         args = []
         if cwd:
             args.append('-d %s' % util.shellquote(cwd))
@@ -261,14 +261,24 @@
                     ui.warn(pf + '\n')
                     printed_file = True
                 ui.warn(line + '\n')
-            
-        if dopatch == 'filter':
-            os.unlink(patchname)
-
         code = fp.close()
         if code:
             raise util.Abort(_("patch command failed: %s") %
                              util.explain_exit(code)[0])
+        return files, fuzz
+
+    (dopatch, gitpatches) = readgitpatch(patchname)
+
+    if dopatch:
+        if dopatch == 'filter':
+            patchname = dogitpatch(patchname, gitpatches, cwd=cwd)
+        try:
+            files, fuzz = __patch(patchname)
+        finally:
+            if dopatch == 'filter':
+                os.unlink(patchname)
+    else:
+        files, fuzz = {}, False
 
     for gp in gitpatches:
         files[gp.path] = (gp.op, gp)