--- /usr/local/lib/python2.6/shutil.py 2008-12-13 03:54:30.000000000 +0200 +++ shutil_patched.py 2008-12-29 10:28:35.000000000 +0200 @@ -201,6 +201,12 @@ onerror(os.path.islink, path, sys.exc_info()) # can't continue even if onerror hook returns return + try: + path_inode_orig = os.lstat(path).st_ino + except os.error, err: + onerror(os.lstat, path, sys.exc_info()) + # can't continue even if onerror hook returns + return names = [] try: names = os.listdir(path) @@ -220,6 +226,25 @@ except os.error, err: onerror(os.remove, fullname, sys.exc_info()) try: + s = os.lstat(path) + path_inode_new = s.st_ino + mode = s.st_mode + if not stat.S_ISDIR(mode): + raise OSError("Path changed from directory to something else " + "during execution") + except os.error, err: + onerror(os.lstat, path, sys.exc_info()) + # can't continue even if onerror hook returns + return + try: + if path_inode_orig != path_inode_new: + # avoid race conditions, see bug #4489 + raise OSError("Directory inode changed during execution") + except OSError: + onerror(os.path.islink, path, sys.exc_info()) + # can't continue even if onerror hook returns + return + try: os.rmdir(path) except os.error: onerror(os.rmdir, path, sys.exc_info())