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)
|
||||
|
||||
|
||||
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:
|
||||
archive_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
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():
|
||||
continue
|
||||
|
||||
relative_path = source_file.relative_to(resourcepack_root).as_posix()
|
||||
archive.write(source_file, relative_path)
|
||||
relative_path = source_file.relative_to(resourcepack_root)
|
||||
archive.write(source_file, relative_path.as_posix())
|
||||
|
||||
|
||||
def request_json(request: urllib.request.Request) -> dict[str, object]:
|
||||
|
||||
Reference in New Issue
Block a user