Index: Lib/shutil.py =================================================================== --- Lib/shutil.py (revision 86804) +++ Lib/shutil.py (working copy) @@ -68,7 +68,25 @@ fdst.write(buf) def _samefile(src, dst): - # Macintosh, Unix. + if sys.platform == "win32": + # Windows hard links need to be compared when open. os.path.samefile + # does not work in this case. + try: + link = False + for f in (src, dst): + if os.stat(src).st_nlink > 0: + link |= True + except WindowsError: + return False + + if link: + try: + with open(src, "r") as f1, open(dst, "r") as f2: + return os.path.sameopenfile(f1.fileno(), f2.fileno()) + except (OSError, IOError): + return False + + # Macintosh, Unix, Windows regular files. if hasattr(os.path, 'samefile'): try: return os.path.samefile(src, dst)