[PATCH] rename under the other OS
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[PATCH] rename under the other OS
From: K Thananchayan <thananck@yahoo.com>
Rename fails under windows if dest file exists. This
patch add a rename method to util module that removes
the dest file and retries if initial attempt fails.
manifest hash:
2744d9fd1717e15133b411a269df909fa8ec0faf
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCuNzDywK+sNU5EO8RAsPBAJ9NQN3bTuJvTem5x+utGnoMkhYc0QCbBFSJ
PoMP69H1UnVE6drFlnlFE0s=
=pePw
-----END PGP SIGNATURE-----
--- a/mercurial/hg.py Tue Jun 21 19:33:13 2005 -0800
+++ b/mercurial/hg.py Tue Jun 21 19:36:35 2005 -0800
@@ -338,7 +338,7 @@
else:
if s.st_nlink > 1:
file(f + ".tmp", "wb").write(file(f, "rb").read())
- os.rename(f+".tmp", f)
+ util.rename(f+".tmp", f)
return file(f, mode)
@@ -482,7 +482,7 @@
self.ui.status("attempting to rollback last transaction\n")
transaction.rollback(self.opener, self.join("undo"))
self.dirstate = None
- os.rename(self.join("undo.dirstate"), self.join("dirstate"))
+ util.rename(self.join("undo.dirstate"), self.join("dirstate"))
self.dirstate = dirstate(self.opener, self.ui, self.root)
else:
self.ui.warn("no undo information available\n")
--- a/mercurial/transaction.py Tue Jun 21 19:33:13 2005 -0800
+++ b/mercurial/transaction.py Tue Jun 21 19:36:35 2005 -0800
@@ -12,6 +12,7 @@
# of the GNU General Public License, incorporated herein by reference.
import os
+import util
class transaction:
def __init__(self, opener, journal, after = None):
@@ -46,7 +47,7 @@
self.file.close()
self.entries = []
if self.after:
- os.rename(self.journal, self.after)
+ util.rename(self.journal, self.after)
else:
os.unlink(self.journal)
--- a/mercurial/util.py Tue Jun 21 19:33:13 2005 -0800
+++ b/mercurial/util.py Tue Jun 21 19:36:35 2005 -0800
@@ -7,6 +7,14 @@
import os
+def rename(src, dst):
+ try:
+ os.rename(src, dst)
+ except:
+ os.unlink(dst)
+ os.rename(src, dst)
+
+# Platfor specific varients
if os.name == 'nt':
def pconvert(path):
return path.replace("\\", "/")