From f45d227cda82e55525492b8adace30a8a1ab4f5f Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 16:13:47 +0800 Subject: [PATCH] py2 shutil.copy have no paraamter follow_symlink --- pydu/file.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pydu/file.py b/pydu/file.py index f2eb2b0..1fd840a 100644 --- a/pydu/file.py +++ b/pydu/file.py @@ -98,7 +98,10 @@ def copy(src, dst, ignore_errors=False, follow_symlinks=True): if os.path.isdir(src): shutil.copytree(src, dst, symlinks=not follow_symlinks) else: - shutil.copy(src, dst, follow_symlinks=follow_symlinks) + if not follow_symlinks and os.path.islink(src): + os.symlink(os.readlink(src), dst) + else: + shutil.copy(src, dst) except Exception: if not ignore_errors: raise OSError('Copy {} to {} error'.format(src, dst))