shutil.py 859 B

123456789101112131415161718192021222324252627282930
  1. # flake8: noqa: F405
  2. from shutil import * # noqa: F403
  3. from .compat_utils import passthrough_module
  4. passthrough_module(__name__, 'shutil')
  5. del passthrough_module
  6. import sys
  7. if sys.platform.startswith('freebsd'):
  8. import errno
  9. import os
  10. import shutil
  11. # Workaround for PermissionError when using restricted ACL mode on FreeBSD
  12. def copy2(src, dst, *args, **kwargs):
  13. if os.path.isdir(dst):
  14. dst = os.path.join(dst, os.path.basename(src))
  15. shutil.copyfile(src, dst, *args, **kwargs)
  16. try:
  17. shutil.copystat(src, dst, *args, **kwargs)
  18. except PermissionError as e:
  19. if e.errno != getattr(errno, 'EPERM', None):
  20. raise
  21. return dst
  22. def move(*args, copy_function=copy2, **kwargs):
  23. return shutil.move(*args, copy_function=copy_function, **kwargs)