Skip to content

Commit

Permalink
Add logic to warn if tar compression format is unknown, or not suppor…
Browse files Browse the repository at this point in the history
…ted by WSL1 (#12466)
  • Loading branch information
OneBlue authored Jan 15, 2025
1 parent 7ef2004 commit f007ede
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion distributions/validate-modern.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
X64_ELF_MAGIC = re.compile('^ELF 64-bit.* x86-64, version 1')
ARM64_ELF_MAGIC = re.compile('^ELF 64-bit.* ARM aarch64, version 1')

KNOWN_TAR_FORMATS = {'^XZ compressed data.*': False, '^gzip compressed data.*': True}

DISCOURAGED_SYSTEM_UNITS = ['systemd-resolved.service',
'systemd-networkd.service',
'systemd-tmpfiles-setup.service',
Expand Down Expand Up @@ -406,6 +408,7 @@ def read_url(flavor: str, name: str, url: dict, elf_magic):
if not url['Url'].endswith('.wsl'):
warning(flavor, name, f'Url does not point to a .wsl file: {url["Url"]}')

tar_format = None
if url['Url'].startswith('file://'):
with open(url['Url'].replace('file:///', '').replace('file://', ''), 'rb') as fd:
while True:
Expand All @@ -415,6 +418,9 @@ def read_url(flavor: str, name: str, url: dict, elf_magic):

hash.update(e)

if tar_format is None:
tar_format = MAGIC.from_buffer(e)

fd.seek(0, 0)
read_tar(flavor, name, fd, elf_magic)
else:
Expand All @@ -426,6 +432,9 @@ def read_url(flavor: str, name: str, url: dict, elf_magic):
file.write(e)
hash.update(e)

if tar_format is None:
tar_format = MAGIC.from_buffer(e)

file.seek(0, 0)
read_tar(flavor, name, file, elf_magic)

Expand All @@ -443,7 +452,11 @@ def read_url(flavor: str, name: str, url: dict, elf_magic):
else:
click.secho(f'Hash for {url["Url"]} matches ({expected_sha})', fg='green')


known_format = next((value for key, value in KNOWN_TAR_FORMATS.items() if re.match(key, tar_format)), None)
if known_format is None:
error(flavor, name, f'Unknown tar format: {tar_format}')
elif not known_format:
warning(flavor, name, f'Tar format not supported by WSL1: {tar_format}')

def error(flavor: str, distribution: str, message: str):
global errors
Expand Down

0 comments on commit f007ede

Please sign in to comment.