Restrict release archive contents
This commit is contained in:
@@ -19,16 +19,29 @@ def log(message: str) -> None:
|
|||||||
print(message, file=sys.stderr, flush=True)
|
print(message, file=sys.stderr, flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
def add_payload_file(archive: zipfile.ZipFile, source_file: Path, relative_path: Path) -> None:
|
||||||
|
if source_file.exists() and source_file.is_file():
|
||||||
|
archive.write(source_file, relative_path.as_posix())
|
||||||
|
|
||||||
|
|
||||||
def zip_resourcepack(resourcepack_root: Path, archive_path: Path) -> None:
|
def zip_resourcepack(resourcepack_root: Path, archive_path: Path) -> None:
|
||||||
archive_path.parent.mkdir(parents=True, exist_ok=True)
|
archive_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
with zipfile.ZipFile(archive_path, mode="w", compression=zipfile.ZIP_DEFLATED) as archive:
|
with zipfile.ZipFile(archive_path, mode="w", compression=zipfile.ZIP_DEFLATED) as archive:
|
||||||
for source_file in sorted(resourcepack_root.rglob("*")):
|
add_payload_file(archive, resourcepack_root / "pack.mcmeta", Path("pack.mcmeta"))
|
||||||
|
add_payload_file(archive, resourcepack_root / "pack.png", Path("pack.png"))
|
||||||
|
|
||||||
|
for directory_name in ("assets", "data"):
|
||||||
|
directory = resourcepack_root / directory_name
|
||||||
|
if not directory.is_dir():
|
||||||
|
continue
|
||||||
|
|
||||||
|
for source_file in sorted(directory.rglob("*")):
|
||||||
if source_file.is_dir():
|
if source_file.is_dir():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
relative_path = source_file.relative_to(resourcepack_root).as_posix()
|
relative_path = source_file.relative_to(resourcepack_root)
|
||||||
archive.write(source_file, relative_path)
|
archive.write(source_file, relative_path.as_posix())
|
||||||
|
|
||||||
|
|
||||||
def request_json(request: urllib.request.Request) -> dict[str, object]:
|
def request_json(request: urllib.request.Request) -> dict[str, object]:
|
||||||
|
|||||||
Reference in New Issue
Block a user