Fix an issue that causes create symlink failed when installing java on unix-like platforms.

This commit is contained in:
wei committed 2026-10-18 21:42:54 +08:00
1 parent 8bde4ef753
commit 1754b01230
15 files changed
+600 -77

No files matched your search

+9
View File
@@ -160,6 +160,12 @@ class FileObject:
def exists(self):
return self.__path.exists()
def invalidate_hash_cache(self):
self.__sha1 = None
self.__sha256 = None
self.__sha512 = None
self.__md5 = None
def download_file(file: FileObject, overwrite=True, progress_callback: Callable[int]=None) -> FileObject | Exception:
"""
@@ -180,6 +186,7 @@ def download_file(file: FileObject, overwrite=True, progress_callback: Callable[
logger.debug("Downloading file {} to {}".format(file.url, file))
file.invalidate_hash_cache() # Clean cache hash
try:
with requests.get(file.url, stream=True) as r:
r.raise_for_status()
@@ -203,6 +210,8 @@ def download_file(file: FileObject, overwrite=True, progress_callback: Callable[
raise DownloadException(
"An error occurred while downloading file {}. {}".format(file.url, e)
)
finally:
file.invalidate_hash_cache()
if file.expected_sha256 and not file.verify_sha256():
raise HashMismatchException("sha256", file.sha256, file.expected_sha256, file.posix_path)
+2 -2
View File
@@ -24,8 +24,8 @@ class LauncherHTTPException(LauncherException):
class HashMismatchException(Exception):
def __init__(self, hash_name, got_hash, expected_hash, filepath: str | Path):
if type(filepath) == Path: filepath = Path(filepath).absolute().as_posix()
self.message = "File {} hash mismatch. Expected hash {}. Got hash {} ({})".format(filepath, got_hash,
expected_hash, hash_name)
self.message = "File {} hash mismatch. Expected hash {}. Got hash {} ({})".format(filepath, expected_hash, got_hash,
hash_name)
super().__init__(self.message)
class UnsupportedPlatformException(LauncherException):