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
Hard link or copy ivy and coursier cache #6246
Changes from 11 commits
13cb365
3bb05d6
3df6d36
661a7f2
18c777c
7ecd27f
1426c79
7406b39
bb477a8
63a9284
99b74ad
997b0de
d53afe4
a1b17a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ | |
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import errno | ||
import os | ||
import random | ||
import shutil | ||
from uuid import uuid4 | ||
|
||
from pants.util.contextutil import temporary_file | ||
|
||
|
@@ -37,3 +39,33 @@ def line_count(filename): | |
'nosize': lambda srcs: 0, | ||
'random': lambda srcs: random.randint(0, 10000), | ||
} | ||
|
||
|
||
# Copied from pex for JVM related code not to depend on pex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment could be dropped; especially if you add a unit test - which would be great. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment removed and tests added |
||
# https://github.com/pantsbuild/pex/blob/d1f946c8b46f8c5123b01bcd376c87bb67c8a884/pex/common.py#L25-L50 | ||
def safe_hardlink_or_copy(source, dest, overwrite=False): | ||
def do_copy(): | ||
temp_dest = dest + uuid4().hex | ||
shutil.copyfile(source, temp_dest) | ||
os.rename(temp_dest, dest) | ||
|
||
# If the platform supports hard-linking, use that and fall back to copying. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment and check are very out of character for the codebase - since we don't support windows. I'm fine with it staying perhaps, but it does add complexity to the function and the resulting test, which will need to mock or somesuch to test the else branch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Windows portion removed. |
||
# Windows does not support hard-linking. | ||
if hasattr(os, 'link'): | ||
try: | ||
os.link(source, dest) | ||
except OSError as e: | ||
if e.errno == errno.EEXIST: | ||
# File already exists. If overwrite=True, write otherwise skip. | ||
if overwrite: | ||
do_copy() | ||
elif e.errno == errno.EXDEV: | ||
# Hard link across devices, fall back on copying | ||
do_copy() | ||
else: | ||
raise | ||
elif os.path.exists(dest): | ||
if overwrite: | ||
do_copy() | ||
else: | ||
do_copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably isn't necessary any more (but is probably worth keeping anyway, because caching symlink traversals is scary)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Good catch!