[PATCH 2 of 2 STABLE] store: add auto detection for hardlink count blindness (issue1866)

Adrian Buehlmann adrian at cadifra.com
Wed Nov 3 15:44:42 CDT 2010


On 03.11.2010 21:18, Adrian Buehlmann wrote:
> On 03.11.2010 17:52, Matt Mackall wrote:
>> ..and then I went on to point out that we shouldn't even be testing
>> nlinks on 'w'rite (where COW is pointless), but only on 'a'ppend. On
>> write, we should (and usually do, see localrepo.wwrite) unconditionally
>> break links by first unlinking any existing file.
> 
> So, should we do
> 
> diff -r 0e0a52bd58f9 mercurial/util.py
> --- a/mercurial/util.py Thu Oct 21 16:04:34 2010 -0500
> +++ b/mercurial/util.py Wed Nov 03 21:13:03 2010 +0100
> @@ -871,7 +871,10 @@
>              if atomictemp:
>                  return atomictempfile(f, mode, self.createmode)
>              if nlink > 1:
> -                rename(mktempcopy(f), f)
> +                if 'w' in mode:
> +                    os.unlink(f)
> +                else:
> +                    rename(mktempcopy(f), f)
>          fp = posixfile(f, mode)
>          if nlink == 0:
>              self._fixfilemode(f)
> 
> as a first step?

Or rather

diff -r 0e0a52bd58f9 mercurial/util.py
--- a/mercurial/util.py Thu Oct 21 16:04:34 2010 -0500
+++ b/mercurial/util.py Wed Nov 03 21:42:17 2010 +0100
@@ -871,7 +871,11 @@
             if atomictemp:
                 return atomictempfile(f, mode, self.createmode)
             if nlink > 1:
-                rename(mktempcopy(f), f)
+                if 'w' in mode:
+                    os.unlink(f)
+                    nlink = 0
+                else:
+                    rename(mktempcopy(f), f)
         fp = posixfile(f, mode)
         if nlink == 0:
             self._fixfilemode(f)

(note the additional 'nlink = 0')


More information about the Mercurial-devel mailing list