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

Fix symlinking logic in the presence of broken links. #7791

Merged
merged 2 commits into from May 24, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -41,7 +41,7 @@ jar_library(
)

# Running Kythe on JDK8 requires a standalone javac 9 on the bootclasspath.
# This jar is published to the same custom rpeo as the Kythe jars.
# This jar is published to the same custom repo as the Kythe jars.
jar_library(
name='javac9',
jars = [jar(org='java', name='javac', rev='9+181-r4173-1')]
@@ -141,6 +141,7 @@ python_library(
':jvm_tool_mixin',
':shader',
'src/python/pants/subsystem',
'src/python/pants/util:dirutil',
]
)

@@ -27,7 +27,7 @@
from pants.java.distribution.distribution import Distribution
from pants.java.jar.jar_dependency import JarDependency
from pants.subsystem.subsystem import Subsystem
from pants.util.dirutil import fast_relpath, safe_mkdir
from pants.util.dirutil import fast_relpath, safe_delete, safe_mkdir
from pants.util.fileutil import safe_hardlink_or_copy
from pants.util.memo import memoized_method, memoized_property

@@ -210,14 +210,13 @@ def dist(self):
get_buildroot())

# Since this code can be run in multi-threading mode due to multiple
# zinc workers, we need to make sure the file operations below is atomic.
# zinc workers, we need to make sure the file operations below are atomic.
with self._lock:
# Create the symlink if it does not exist
if not os.path.exists(jdk_home_symlink):
os.symlink(underlying_dist.home, jdk_home_symlink)
# Recreate if the symlink exists but does not match `underlying_dist.home`.
elif os.readlink(jdk_home_symlink) != underlying_dist.home:
os.remove(jdk_home_symlink)
# Create the symlink if it does not exist, or points to a file that doesn't exist,
# (e.g., a JDK that is no longer present), or points to the wrong JDK.
if (not os.path.exists(jdk_home_symlink) or
os.readlink(jdk_home_symlink) != underlying_dist.home):
safe_delete(jdk_home_symlink) # Safe-delete, in case it's a broken symlink.
os.symlink(underlying_dist.home, jdk_home_symlink)

return Distribution(home_path=jdk_home_symlink)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.