Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change mv to cp when downloading softlinks. #562

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dpgen/dispatcher/LocalContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ def download(self,
pass
elif (os.path.exists(rfile)) and (not os.path.exists(lfile)) :
# trivial case, download happily
shutil.move(rfile, lfile)
# If the file to be downloaded is a softlink, `cp` should be performed instead of `mv`.
# Otherwise, `lfile` is still a file linked to some original file,
# and when this file's removed, `lfile` will be invalid.
if os.path.islink(rfile):
shutil.copyfile(rfile,lfile)
else:
shutil.move(rfile, lfile)
elif (os.path.exists(rfile)) and (os.path.exists(lfile)) :
# both exists, replace!
dlog.info('find existing %s, replacing by %s' % (lfile, rfile))
Expand Down