Skip to content

Commit dd1b8e1

Browse files
authored
Fix #6 (#7)
* Fix #6 * Fix github actions * Version bump
1 parent 44af8ef commit dd1b8e1

5 files changed

Lines changed: 34 additions & 10 deletions

File tree

‎.github/workflows/build.yaml‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ jobs:
2222
for i in {1..100};do
2323
echo "hello world" >> test/test.txt
2424
done
25-
dd if=/dev/zero of=test.ext4 count=1024 bs=1024
26-
mkfs.ext4 test.ext4 -d test
25+
dd if=/dev/zero of=test.ext4.tmp count=1024 bs=1024
26+
mkfs.ext4 test.ext4.tmp -d test
27+
echo -n F > test.ext4
28+
cat test.ext4.tmp >> test.ext4
2729
- uses: actions/upload-artifact@v4
2830
with:
2931
name: test.ext4
30-
path: test.ext4
32+
path: |
33+
test.ext4
34+
test.ext4.tmp
3135
if-no-files-found: error
3236
test:
3337
name: Test on ${{ matrix.os }} python ${{ matrix.python }}

‎ext4/struct.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def field_type(cls, name):
4141
return None
4242

4343
def read_from_volume(self):
44-
self.volume.stream.seek(self.offset)
45-
data = self.volume.stream.read(sizeof(self))
44+
self.volume.seek(self.offset)
45+
data = self.volume.read(sizeof(self))
4646
memmove(addressof(self), data, sizeof(self))
4747

4848
@property

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ext4"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
authors = [
55
{ name="Eeems", email="eeems@eeems.email" },
66
]

‎test.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
import sys
45
import ext4
56

@@ -43,9 +44,26 @@ def _assert(source: str):
4344
test_path_tuple("/test/test", (b"test", b"test"))
4445
test_path_tuple(b"/test/test", (b"test", b"test"))
4546

47+
offset = os.path.getsize("test.ext4") - os.path.getsize("test.ext4.tmp")
48+
_assert("offset > 0")
4649
with open("test.ext4", "rb") as f:
50+
try:
51+
print("check MagicError: ", end="")
52+
_ = ext4.Volume(f, offset=0)
53+
FAILED = True
54+
print("fail")
55+
print(" MagicError not raised")
56+
except ext4.struct.MagicError:
57+
print("pass")
58+
59+
except Exception as e:
60+
FAILED = True
61+
print("fail")
62+
print(" ", end="")
63+
print(e)
64+
4765
# Extract specific file
48-
volume = ext4.Volume(f, offset=0)
66+
volume = ext4.Volume(f, offset=offset)
4967
inode = cast(ext4.File, volume.inode_at("/test.txt"))
5068
_assert("isinstance(inode, ext4.File)")
5169
b = inode.open()

‎test.sh‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ if ! [ -f test.ext4 ];then
2020
for i in {1..100};do
2121
echo "hello world" >> "$tmp_dir"/test.txt
2222
done
23-
dd if=/dev/zero of=test.ext4 count=1024 bs=1024
24-
trap "rm test.ext4" EXIT
25-
mkfs.ext4 test.ext4 -d "$tmp_dir"
23+
trap "rm -f test.ext4{,.tmp}" EXIT
24+
dd if=/dev/zero of=test.ext4.tmp count=1024 bs=1024
25+
mkfs.ext4 test.ext4.tmp -d "$tmp_dir"
26+
echo -n F > test.ext4
27+
cat test.ext4.tmp >> test.ext4
2628
fi
2729
python test.py

0 commit comments

Comments
 (0)