rename: simplify forced renaming
authorMatt Mackall <mpm@selenic.com>
Mon, 16 Feb 2009 17:37:23 -0600
changeset 7780 9892c4d94fb7
parent 7779 e899ead7b8ae
child 7781 a45206455d85
rename: simplify forced renaming This should help work around virus scanner issues with rename on Windows.
mercurial/util.py
--- a/mercurial/util.py	Mon Feb 16 17:37:23 2009 -0600
+++ b/mercurial/util.py	Mon Feb 16 17:37:23 2009 -0600
@@ -740,12 +740,10 @@
         # on windows, rename to existing file is not allowed, so we
         # must delete destination first. but if file is open, unlink
         # schedules it for delete but does not delete it. rename
-        # happens immediately even for open files, so we create
-        # temporary file, delete it, rename destination to that name,
-        # then delete that. then rename is safe to do.
-        fd, temp = tempfile.mkstemp(dir=os.path.dirname(dst) or '.')
-        os.close(fd)
-        os.unlink(temp)
+        # happens immediately even for open files, so we rename
+        # destination to a temporary name, then delete that. then
+        # rename is safe to do.
+        temp = dst + "-force-rename"
         os.rename(dst, temp)
         os.unlink(temp)
         os.rename(src, dst)