Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 54886) +++ Modules/posixmodule.c (working copy) @@ -2451,8 +2451,10 @@ PyErr_Clear(); else { Py_BEGIN_ALLOW_THREADS - result = MoveFileW(PyUnicode_AsUnicode(o1), - PyUnicode_AsUnicode(o2)); + result = MoveFileExW(PyUnicode_AsUnicode(o1), + PyUnicode_AsUnicode(o2), + MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING); + Py_END_ALLOW_THREADS Py_DECREF(o1); Py_DECREF(o2); @@ -2465,7 +2467,7 @@ if (!PyArg_ParseTuple(args, "ss:rename", &p1, &p2)) return NULL; Py_BEGIN_ALLOW_THREADS - result = MoveFileA(p1, p2); + result = MoveFileExA(p1, p2, MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING); Py_END_ALLOW_THREADS if (!result) return win32_error("rename", NULL); Index: Lib/test/test_os.py =================================================================== --- Lib/test/test_os.py (revision 54885) +++ Lib/test/test_os.py (working copy) @@ -437,6 +437,14 @@ def test_rename(self): self.assertRaises(WindowsError, os.rename, test_support.TESTFN, test_support.TESTFN+".bak") + def test_rename2(self): + import tempfile + fd, fname1 = tempfile.mkstemp() + os.close(fd) + fd, fname2 = tempfile.mkstemp() + os.close(fd) + os.rename(fname1, fname2) + def test_remove(self): self.assertRaises(WindowsError, os.remove, test_support.TESTFN) Index: Doc/lib/libos.tex =================================================================== --- Doc/lib/libos.tex (revision 54885) +++ Doc/lib/libos.tex (working copy) @@ -995,10 +995,8 @@ user has permission. The operation may fail on some \UNIX{} flavors if \var{src} and \var{dst} are on different filesystems. If successful, the renaming will be an atomic operation (this is a -\POSIX{} requirement). On Windows, if \var{dst} already exists, -\exception{OSError} will be raised even if it is a file; there may be -no way to implement an atomic rename when \var{dst} names an existing -file. +\POSIX{} requirement). On Windows, if \var{dst} already exists +and is on a separate volume, the renaming may not be atomic. Availability: Macintosh, \UNIX, Windows. \end{funcdesc}