-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lz4 and lzma compressed images (#27)
* Add simple automated test * Add missing LZMA support * Fix broken LZ4 support Trying to access an LZ4-compressed squashfs file would result in: LZ4F_getFrameInfo failed with code: ERROR_frameType_unknown
- Loading branch information
Showing
3 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: '**' | ||
tags-ignore: '**' | ||
pull_request: | ||
|
||
jobs: | ||
Tests: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
python-version: ['3.7', '3.12'] | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- uses: msys2/setup-msys2@v2 | ||
if: startsWith( matrix.os, 'windows' ) | ||
|
||
- name: Install Dependencies (Linux) | ||
if: startsWith( matrix.os, 'ubuntu' ) | ||
run: | | ||
sudo apt-get -y install liblzo2-dev | ||
- name: Install pip Dependencies | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
python3 -m pip install --upgrade wheel setuptools twine pytest python-lzo lz4 zstandard | ||
- name: Test Installation From Tarball | ||
run: | | ||
python3 setup.py clean check build sdist bdist_egg bdist_wheel | ||
twine check dist/* | ||
python3 -m pip install "$( find dist -name '*.tar.gz' | head -1 )" | ||
- name: Unit Tests | ||
run: | | ||
pytest PySquashfsImage/tests/test_*.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import io | ||
import os | ||
import subprocess | ||
import tarfile | ||
import tempfile | ||
|
||
import pytest | ||
|
||
import PySquashfsImage | ||
|
||
|
||
def _createFile(tarArchive, name, contents): | ||
tinfo = tarfile.TarInfo(name) | ||
tinfo.size = len(contents) | ||
tarArchive.addfile(tinfo, io.BytesIO(contents.encode())) | ||
|
||
|
||
@pytest.mark.parametrize("compression", ["", "gzip", "lz4", "lzma", "lzo", "xz", "zstd"]) | ||
def test_compressions(compression): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
tarPath = os.path.join(tmpdir, "foo.tar") | ||
with tarfile.open(name=tarPath, mode='w:') as tarArchive: | ||
_createFile(tarArchive, "foo", "bar") | ||
|
||
squashfsPath = os.path.join(tmpdir, f"foo.{compression if compression else 'no-compression'}.squashfs") | ||
compressionOptions = ["-comp", compression] if compression else ["-noI", "-noId", "-noD", "-noF", "-noX"] | ||
process = subprocess.Popen( | ||
["sqfstar"] + compressionOptions + [squashfsPath], stdin=subprocess.PIPE, stdout=subprocess.PIPE | ||
) | ||
with open(tarPath, 'rb') as file: | ||
process.communicate(file.read()) | ||
|
||
with open(squashfsPath, 'rb') as file, PySquashfsImage.SquashFsImage(file) as image: | ||
entries = list(iter(image)) | ||
assert len(entries) == 2 | ||
assert entries[0].path == "/" | ||
assert entries[1].path == "/foo" | ||
assert image.read_file(entries[1].inode) == b"bar" |