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

check sha1 for forge/neoforge maven #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions meta/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,12 @@ def default_session():
sess.headers.update({"User-Agent": "PrismLauncherMeta/1.0"})

return sess


def remove_files(file_paths):
for file_path in file_paths:
try:
if os.path.isfile(file_path):
os.remove(file_path)
except Exception as e:
print(e)
20 changes: 19 additions & 1 deletion meta/run/update_forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@

from pydantic import ValidationError

from meta.common import upstream_path, ensure_upstream_dir, default_session
from meta.common import (
upstream_path,
ensure_upstream_dir,
default_session,
remove_files,
)
from meta.common.forge import (
JARS_DIR,
INSTALLER_INFO_DIR,
Expand Down Expand Up @@ -292,6 +297,19 @@ def main():
UPSTREAM_DIR + "/forge/version_manifests/%s.json" % version.long_version
)

if not os.path.isfile(jar_path):
remove_files([profile_path, installer_info_path])
else:
fileSha1 = filehash(jar_path, hashlib.sha1)
try:
rfile = sess.get(version.url() + ".sha1")
rfile.raise_for_status()
if fileSha1 != rfile.text.strip():
remove_files([jar_path, profile_path, installer_info_path])
except Exception as e:
eprint("Failed to check sha1 %s" % version.url())
eprint("Error is %s" % e)

installer_refresh_required = not os.path.isfile(
profile_path
) or not os.path.isfile(installer_info_path)
Expand Down
20 changes: 19 additions & 1 deletion meta/run/update_neoforge.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

from pydantic import ValidationError

from meta.common import upstream_path, ensure_upstream_dir, default_session
from meta.common import (
upstream_path,
ensure_upstream_dir,
default_session,
remove_files,
)
from meta.common.neoforge import (
JARS_DIR,
INSTALLER_INFO_DIR,
Expand Down Expand Up @@ -243,6 +248,19 @@ def main():
UPSTREAM_DIR + "/neoforge/version_manifests/%s.json" % version.long_version
)

if not os.path.isfile(jar_path):
remove_files([profile_path, installer_info_path])
else:
fileSha1 = filehash(jar_path, hashlib.sha1)
try:
rfile = sess.get(version.url() + ".sha1")
rfile.raise_for_status()
if fileSha1 != rfile.text.strip():
remove_files([jar_path, profile_path, installer_info_path])
except Exception as e:
eprint("Failed to check sha1 %s" % version.url())
eprint("Error is %s" % e)

installer_refresh_required = not os.path.isfile(
profile_path
) or not os.path.isfile(installer_info_path)
Expand Down
2 changes: 2 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function launcher_git() {
currentDate=$(date -I)

upstream_git reset --hard HEAD || exit 1
upstream_git pull

python -m meta.run.update_mojang || fail_in
python -m meta.run.update_forge || fail_in
Expand All @@ -57,6 +58,7 @@ if [ "${DEPLOY_TO_GIT}" = true ]; then
fi

launcher_git reset --hard HEAD || exit 1
launcher_git pull

python -m meta.run.generate_mojang || fail_out
python -m meta.run.generate_forge || fail_out
Expand Down