fix symlink error on windows (#41)

Co-authored-by: qiufeng <qiufeng3217@gmail.com>
pull/49/head
qiufeng 2022-01-06 15:35:14 +08:00 committed by GitHub
parent d5a9e38efe
commit b6c5fffe8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

2
.gitignore vendored
View File

@ -112,7 +112,7 @@ venv.bak/
*.pkl.json
*.log.json
/work_dirs
/mmcls/.mim
/mmrazor/.mim
# Pytorch
*.pth

View File

@ -131,7 +131,19 @@ def add_mim_extension():
if mode == 'symlink':
src_relpath = osp.relpath(src_path, osp.dirname(tar_path))
os.symlink(src_relpath, tar_path)
try:
os.symlink(src_relpath, tar_path)
except OSError:
# Creating a symbolic link on windows may raise an
# `OSError: [WinError 1314]` due to privilege. If
# the error happens, the src file will be copied
mode = 'copy'
warnings.warn(
f'Failed to create a symbolic link for {src_relpath}, '
f'and it will be copied to {tar_path}')
else:
continue
elif mode == 'copy':
if osp.isfile(src_path):
shutil.copyfile(src_path, tar_path)