diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ddd535e..b672a0f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -22,12 +22,16 @@ jobs: for i in {1..100};do echo "hello world" >> test/test.txt done - dd if=/dev/zero of=test.ext4 count=1024 bs=1024 - mkfs.ext4 test.ext4 -d test + dd if=/dev/zero of=test.ext4.tmp count=1024 bs=1024 + mkfs.ext4 test.ext4.tmp -d test + echo -n F > test.ext4 + cat test.ext4.tmp >> test.ext4 - uses: actions/upload-artifact@v4 with: name: test.ext4 - path: test.ext4 + path: | + test.ext4 + test.ext4.tmp if-no-files-found: error test: name: Test on ${{ matrix.os }} python ${{ matrix.python }} diff --git a/ext4/struct.py b/ext4/struct.py index 220a833..fe2bf39 100644 --- a/ext4/struct.py +++ b/ext4/struct.py @@ -41,8 +41,8 @@ def field_type(cls, name): return None def read_from_volume(self): - self.volume.stream.seek(self.offset) - data = self.volume.stream.read(sizeof(self)) + self.volume.seek(self.offset) + data = self.volume.read(sizeof(self)) memmove(addressof(self), data, sizeof(self)) @property diff --git a/pyproject.toml b/pyproject.toml index ab55fbb..53e6e3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "ext4" -version = "1.1.0" +version = "1.1.1" authors = [ { name="Eeems", email="eeems@eeems.email" }, ] diff --git a/test.py b/test.py index ff3d6cf..995cea8 100644 --- a/test.py +++ b/test.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os import sys import ext4 @@ -43,9 +44,26 @@ def _assert(source: str): test_path_tuple("/test/test", (b"test", b"test")) test_path_tuple(b"/test/test", (b"test", b"test")) +offset = os.path.getsize("test.ext4") - os.path.getsize("test.ext4.tmp") +_assert("offset > 0") with open("test.ext4", "rb") as f: + try: + print("check MagicError: ", end="") + _ = ext4.Volume(f, offset=0) + FAILED = True + print("fail") + print(" MagicError not raised") + except ext4.struct.MagicError: + print("pass") + + except Exception as e: + FAILED = True + print("fail") + print(" ", end="") + print(e) + # Extract specific file - volume = ext4.Volume(f, offset=0) + volume = ext4.Volume(f, offset=offset) inode = cast(ext4.File, volume.inode_at("/test.txt")) _assert("isinstance(inode, ext4.File)") b = inode.open() diff --git a/test.sh b/test.sh index 7cd4a0a..748a665 100755 --- a/test.sh +++ b/test.sh @@ -20,8 +20,10 @@ if ! [ -f test.ext4 ];then for i in {1..100};do echo "hello world" >> "$tmp_dir"/test.txt done - dd if=/dev/zero of=test.ext4 count=1024 bs=1024 - trap "rm test.ext4" EXIT - mkfs.ext4 test.ext4 -d "$tmp_dir" + trap "rm -f test.ext4{,.tmp}" EXIT + dd if=/dev/zero of=test.ext4.tmp count=1024 bs=1024 + mkfs.ext4 test.ext4.tmp -d "$tmp_dir" + echo -n F > test.ext4 + cat test.ext4.tmp >> test.ext4 fi python test.py