(original) (raw)

Index: Lib/shutil.py =================================================================== --- Lib/shutil.py (revision 59335) +++ Lib/shutil.py (working copy) @@ -9,6 +9,12 @@ import stat from os.path import abspath +# To ignore WindowsError on non-Windows systems +try: + WindowsError +except NameError: + WindowsError = None + __all__ = ["copyfileobj","copyfile","copymode","copystat","copy","copy2", "copytree","move","rmtree","Error"] @@ -91,7 +97,14 @@ if os.path.isdir(dst): dst = os.path.join(dst, os.path.basename(src)) copyfile(src, dst) - copystat(src, dst) + try: + copystat(src, dst) + except OSError, err: + # Copying file access times may fail on Windows + if WindowsError is not None and isinstance(err, WindowsError): + pass + else: + raise def copytree(src, dst, symlinks=False): @@ -131,11 +144,12 @@ errors.extend(err.args[0]) try: copystat(src, dst) - except WindowsError: - # can't copy file access times on Windows - pass except OSError, why: - errors.extend((src, dst, str(why))) + # Copying file access times may fail on Windows + if WindowsError is not None and isinstance(err, WindowsError): + pass + else: + errors.extend((src, dst, str(why))) if errors: raise Error, errors