Skip to content

Commit

Permalink
[GR-49553] Ensure download integrity of fetch-jdk
Browse files Browse the repository at this point in the history
PullRequest: mx/1691
  • Loading branch information
zapster committed Nov 10, 2023
2 parents 1cabe68 + 4673f1b commit 054b0ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mx/_impl/mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -19247,7 +19247,7 @@ def alarm_handler(signum, frame):
abort(1, killsig=signal.SIGINT)

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("7.0.3") # GR-48571 Unittest configs are composed with configs from dependencies
version = VersionSpec("7.1.0") # mx fetch-jdk --skip-digest-check

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down
10 changes: 9 additions & 1 deletion src/mx/_impl/mx_fetchjdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def fetch_jdk(args):
if not is_quiet():
if not mx.ask_yes_no(f"Install {artifact} to {final_path}", default='y'):
mx.abort("JDK installation canceled")
if exists(final_path):
if (not settings["digest-check"] or settings["keep-archive"]) and exists(final_path):
if settings["keep-archive"]:
mx.warn("The --keep-archive option is ignored when the JDK is already installed.")
mx.log(f"Requested JDK is already installed at {final_path}")
Expand Down Expand Up @@ -116,6 +116,9 @@ def fetch_jdk(args):
mx.log(f"Archive is located at {archive_target_location}")
part += 1

if settings["digest-check"] and exists(final_path):
mx.log(f"Deleting stale {final_path}...")
mx.rmtree(final_path)
atomic_file_move_with_fallback(join(extracted_path, jdk_root_folder), final_path)

curr_path = final_path
Expand Down Expand Up @@ -333,6 +336,10 @@ def _parse_args(args):
parser.add_argument('--keep-archive', action='store_true', help='keep downloaded JDK archive')
parser.add_argument('--strip-contents-home', action='store_true', help='strip Contents/Home if it exists from installed JDK')
parser.add_argument('--list', action='store_true', help='list the available JDKs and exit')
parser.add_argument('--skip-digest-check', dest='digest_check', action='store_false', help='''
Only check for existence of the destination directory and skip verifying the digest of the downloaded archive.
This is useful to avoid redownloading when the download cache has been deleted.
''')
args = parser.parse_args(args)

if args.to is not None:
Expand Down Expand Up @@ -378,6 +385,7 @@ def _parse_args(args):
settings["keep-archive"] = args.keep_archive

settings["strip-contents-home"] = args.strip_contents_home
settings["digest-check"] = args.digest_check

return settings

Expand Down

0 comments on commit 054b0ef

Please sign in to comment.