MCPcopy Index your code
hub / github.com/python/cpython / copy2

Function copy2

Lib/shutil.py:493–531  ·  view source on GitHub ↗

Copy data and metadata. Return the file's destination. Metadata is copied with copystat(). Please see the copystat function for more information. The destination may be a directory. If follow_symlinks is false, symlinks won't be followed. This resembles GNU's "cp -P src dst".

(src, dst, *, follow_symlinks=True)

Source from the content-addressed store, hash-verified

491 return dst
492
493def copy2(src, dst, *, follow_symlinks=True):
494 """Copy data and metadata. Return the file's destination.
495
496 Metadata is copied with copystat(). Please see the copystat function
497 for more information.
498
499 The destination may be a directory.
500
501 If follow_symlinks is false, symlinks won't be followed. This
502 resembles GNU's "cp -P src dst".
503 """
504 if os.path.isdir(dst):
505 dst = os.path.join(dst, os.path.basename(src))
506
507 if hasattr(_winapi, "CopyFile2"):
508 src_ = os.fsdecode(src)
509 dst_ = os.fsdecode(dst)
510 flags = _winapi.COPY_FILE_ALLOW_DECRYPTED_DESTINATION # for compat
511 if not follow_symlinks:
512 flags |= _winapi.COPY_FILE_COPY_SYMLINK
513 try:
514 _winapi.CopyFile2(src_, dst_, flags)
515 return dst
516 except OSError as exc:
517 if (exc.winerror == _winapi.ERROR_PRIVILEGE_NOT_HELD
518 and not follow_symlinks):
519 # Likely encountered a symlink we aren't allowed to create.
520 # Fall back on the old code
521 pass
522 elif exc.winerror == _winapi.ERROR_ACCESS_DENIED:
523 # Possibly encountered a hidden or readonly file we can't
524 # overwrite. Fall back on old code
525 pass
526 else:
527 raise
528
529 copyfile(src, dst, follow_symlinks=follow_symlinks)
530 copystat(src, dst, follow_symlinks=follow_symlinks)
531 return dst
532
533def ignore_patterns(*patterns):
534 """Function that can be used as copytree() ignore parameter.

Callers 1

_bootstrapFunction · 0.90

Calls 5

copyfileFunction · 0.85
copystatFunction · 0.85
isdirMethod · 0.45
joinMethod · 0.45
basenameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…