Patchwork [1,of,2] util: checknlink should remove file it creates if an exception occurs

login
register
mail settings
Submitter Tony Tung
Date Aug. 19, 2016, 8:58 p.m.
Message ID <2efc5a05d80a6d425376.1471640319@andromeda.local>
Download mbox | patch
Permalink /patch/16363/
State Accepted
Headers show

Comments

Tony Tung - Aug. 19, 2016, 8:58 p.m.
# HG changeset patch
# User Tony Tung <tonytung@merly.org>
# Date 1471638640 25200
#      Fri Aug 19 13:30:40 2016 -0700
# Node ID 2efc5a05d80a6d4253767f2ce0c2fb062ba83cb6
# Parent  9d02bed8477bec7f679d6aeb5b1dd8bcdb80f64d
util: checknlink should remove file it creates if an exception occurs

There's no reason to leave the file behind.
Yuya Nishihara - Aug. 24, 2016, 12:15 p.m.
On Fri, 19 Aug 2016 13:58:39 -0700, ttung@fb.com wrote:
> # HG changeset patch
> # User Tony Tung <tonytung@merly.org>
> # Date 1471638640 25200
> #      Fri Aug 19 13:30:40 2016 -0700
> # Node ID 2efc5a05d80a6d4253767f2ce0c2fb062ba83cb6
> # Parent  9d02bed8477bec7f679d6aeb5b1dd8bcdb80f64d
> util: checknlink should remove file it creates if an exception occurs
> 
> There's no reason to leave the file behind.
> 
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1313,6 +1313,10 @@
>      try:
>          posixfile(f1, 'w').close()
>      except IOError:
> +        try:
> +            os.unlink(f1)
> +        except OSError:
> +            pass
>          return False

I've taken only this from er V0, thanks.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1313,6 +1313,10 @@ 
     try:
         posixfile(f1, 'w').close()
     except IOError:
+        try:
+            os.unlink(f1)
+        except OSError:
+            pass
         return False
 
     f2 = testfile + ".hgtmp2"