def hard_link_or_copy(src, dst):
'''
Create a hard link from `src` to `dst` if possible. Otherwise copy `src` to `dst`.
src:
The source file or directory.
dst:
The destination.
'''
try:
os.link(src, dst)
except OSError as exc:
if exc.errno in (errno.EXDEV, errno.EPERM):
# Cannot create the hard link, maybe src is a directory or src and dst are on
# different devices, so we cannot link.
verbose('Failed to link from "%s" to "%s" as they are not different devices. '
'Copying instead.' %
(src, dst))
copy_path(src, dst)
else:
raise
评论列表
文章目录