[PATCH 2 of 2] localrepo: eliminate os.unlink call in wwrite

Adrian Buehlmann adrian at cadifra.com
Sat Dec 4 06:39:59 CST 2010

# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1291463926 -3600
# Node ID a68d37f33c943b32bae677c8ef117c4268d10f79
# Parent  d117e5fec89474724361f2618eddbae350ba29d1
localrepo: eliminate os.unlink call in wwrite

The opener already unlinks the filename before 'w'riting, for both
the symlink and the normal file case.

The effect of resetting the flags for normal files is now achieved
by setting the new resetflags parameter of the opener's __call__
function to True.

Avoids tripping issue2524 on Windows (os.unlink followed by a write).

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -629,14 +629,10 @@ class localrepository(repo.repository):
     def wwrite(self, filename, data, flags):
         data = self._filter(self._decodefilterpats, filename, data)
-        try:
-            os.unlink(self.wjoin(filename))
-        except OSError:
-            pass
         if 'l' in flags:
             self.wopener.symlink(data, filename)
-            self.wopener(filename, 'w').write(data)
+            self.wopener(filename, 'w', resetflags=True).write(data)
             if 'x' in flags:
                 util.set_flags(self.wjoin(filename), False, True)

More information about the Mercurial-devel mailing list