dissect.extfs 3.12__tar.gz → 3.13.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/PKG-INFO +2 -2
  2. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect/extfs/c_ext.py +2 -0
  3. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect/extfs/c_jdb2.py +2 -0
  4. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect/extfs/extfs.py +29 -29
  5. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect/extfs/journal.py +6 -3
  6. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect.extfs.egg-info/PKG-INFO +2 -2
  7. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/pyproject.toml +49 -5
  8. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/conftest.py +10 -5
  9. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/test_exceptions.py +3 -1
  10. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/test_ext4.py +12 -8
  11. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tox.ini +4 -10
  12. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/.gitattributes +0 -0
  13. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/COPYRIGHT +0 -0
  14. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/LICENSE +0 -0
  15. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/MANIFEST.in +0 -0
  16. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/README.md +0 -0
  17. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect/extfs/__init__.py +2 -2
  18. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect/extfs/exceptions.py +0 -0
  19. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect.extfs.egg-info/SOURCES.txt +0 -0
  20. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect.extfs.egg-info/dependency_links.txt +0 -0
  21. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect.extfs.egg-info/requires.txt +0 -0
  22. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/dissect.extfs.egg-info/top_level.txt +0 -0
  23. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/setup.cfg +0 -0
  24. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/__init__.py +0 -0
  25. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/data/ext4.bin.gz +0 -0
  26. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/data/ext4_sparse.bin.gz +0 -0
  27. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/data/ext4_symlink_test1.bin.gz +0 -0
  28. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/data/ext4_symlink_test2.bin.gz +0 -0
  29. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/data/ext4_symlink_test3.bin.gz +0 -0
  30. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/docs/Makefile +0 -0
  31. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/docs/conf.py +0 -0
  32. {dissect_extfs-3.12 → dissect_extfs-3.13.dev1}/tests/docs/index.rst +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dissect.extfs
3
- Version: 3.12
3
+ Version: 3.13.dev1
4
4
  Summary: A Dissect module implementing a parser for the ExtFS file system, the native filesystem for Linux operating systems
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import stat
2
4
 
3
5
  from dissect.cstruct import cstruct
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from dissect.cstruct import cstruct
2
4
 
3
5
  jdb2_def = """
@@ -4,9 +4,8 @@ import io
4
4
  import logging
5
5
  import os
6
6
  import stat
7
- from datetime import datetime
8
7
  from functools import lru_cache
9
- from typing import BinaryIO, Iterator, Optional, Union
8
+ from typing import TYPE_CHECKING, BinaryIO
10
9
  from uuid import UUID
11
10
 
12
11
  from dissect.util import ts
@@ -29,6 +28,10 @@ from dissect.extfs.exceptions import (
29
28
  )
30
29
  from dissect.extfs.journal import JDB2
31
30
 
31
+ if TYPE_CHECKING:
32
+ from collections.abc import Iterator
33
+ from datetime import datetime
34
+
32
35
  log = logging.getLogger(__name__)
33
36
  log.setLevel(os.getenv("DISSECT_LOG_EXTFS", "CRITICAL"))
34
37
 
@@ -114,7 +117,7 @@ class ExtFS:
114
117
 
115
118
  return self._journal
116
119
 
117
- def get(self, path: Union[str, int], node: Optional[INode] = None) -> INode:
120
+ def get(self, path: str | int, node: INode | None = None) -> INode:
118
121
  if isinstance(path, int):
119
122
  return self.get_inode(path)
120
123
 
@@ -139,9 +142,9 @@ class ExtFS:
139
142
  def get_inode(
140
143
  self,
141
144
  inum: int,
142
- filename: Optional[str] = None,
143
- filetype: Optional[int] = None,
144
- parent: Optional[INode] = None,
145
+ filename: str | None = None,
146
+ filetype: int | None = None,
147
+ parent: INode | None = None,
145
148
  lazy: bool = False,
146
149
  ) -> INode:
147
150
  if inum < c_ext.EXT2_BAD_INO or inum > self.sb.s_inodes_count:
@@ -181,9 +184,9 @@ class INode:
181
184
  self,
182
185
  extfs: ExtFS,
183
186
  inum: int,
184
- filename: Optional[str] = None,
185
- filetype: Optional[int] = None,
186
- parent: Optional[INode] = None,
187
+ filename: str | None = None,
188
+ filetype: int | None = None,
189
+ parent: INode | None = None,
187
190
  ):
188
191
  self.extfs = extfs
189
192
  self.inum = inum
@@ -248,10 +251,7 @@ class INode:
248
251
  if not self._link_inode:
249
252
  # Relative lookups work because . and .. are actual directory entries
250
253
  link = self.link
251
- if link.startswith("/"):
252
- relnode = None
253
- else:
254
- relnode = self.parent
254
+ relnode = None if link.startswith("/") else self.parent
255
255
  self._link_inode = self.extfs.get(self.link, relnode)
256
256
  return self._link_inode
257
257
 
@@ -320,14 +320,14 @@ class INode:
320
320
  return ts.from_unix(self.inode.i_dtime)
321
321
 
322
322
  @property
323
- def crtime(self) -> Optional[datetime]:
323
+ def crtime(self) -> datetime | None:
324
324
  time_ns = self.crtime_ns
325
325
  if time_ns is None:
326
326
  return None
327
327
  return ts.from_unix_ns(time_ns)
328
328
 
329
329
  @property
330
- def crtime_ns(self) -> Optional[int]:
330
+ def crtime_ns(self) -> int | None:
331
331
  if self.extfs.sb.s_inode_size <= 128:
332
332
  return None
333
333
 
@@ -370,7 +370,7 @@ class INode:
370
370
  offset += direntry.rec_len
371
371
  buf.seek(offset)
372
372
 
373
- def dataruns(self) -> list[tuple[Optional[int], int]]:
373
+ def dataruns(self) -> list[tuple[int | None, int]]:
374
374
  if not self._runlist:
375
375
  expected_runs = (self.size + self.extfs.block_size - 1) // self.extfs.block_size
376
376
 
@@ -446,7 +446,7 @@ class INode:
446
446
  return self._runlist
447
447
 
448
448
  def open(self) -> BinaryIO:
449
- if self.inode.i_flags & c_ext.EXT4_INLINE_DATA_FL or self.filetype == stat.S_IFLNK and self.size < 60:
449
+ if self.inode.i_flags & c_ext.EXT4_INLINE_DATA_FL or (self.filetype == stat.S_IFLNK and self.size < 60):
450
450
  buf = io.BytesIO(memoryview(self.inode.i_block)[: self.size])
451
451
  # Need to add a size attribute to maintain compatibility with dissect streams
452
452
  buf.size = self.size
@@ -478,21 +478,21 @@ def _parse_indirect(inode: INode, offset: int, num_blocks: int, level: int) -> l
478
478
  return [0] * read_blocks
479
479
  inode.extfs.fh.seek(offset * inode.extfs.block_size)
480
480
  return c_ext.uint32[read_blocks](inode.extfs.fh)
481
- else:
482
- blocks = []
483
481
 
484
- max_level_blocks = offsets_per_block**level
485
- blocks_per_nest = max_level_blocks // offsets_per_block
486
- read_blocks = (num_blocks + blocks_per_nest - 1) // blocks_per_nest
487
- read_blocks = min(read_blocks, offsets_per_block)
482
+ blocks = []
488
483
 
489
- inode.extfs.fh.seek(offset * inode.extfs.block_size)
490
- for addr in c_ext.uint32[read_blocks](inode.extfs.fh):
491
- parsed_blocks = _parse_indirect(inode, addr, num_blocks, level - 1)
492
- num_blocks -= len(parsed_blocks)
493
- blocks.extend(parsed_blocks)
484
+ max_level_blocks = offsets_per_block**level
485
+ blocks_per_nest = max_level_blocks // offsets_per_block
486
+ read_blocks = (num_blocks + blocks_per_nest - 1) // blocks_per_nest
487
+ read_blocks = min(read_blocks, offsets_per_block)
488
+
489
+ inode.extfs.fh.seek(offset * inode.extfs.block_size)
490
+ for addr in c_ext.uint32[read_blocks](inode.extfs.fh):
491
+ parsed_blocks = _parse_indirect(inode, addr, num_blocks, level - 1)
492
+ num_blocks -= len(parsed_blocks)
493
+ blocks.extend(parsed_blocks)
494
494
 
495
- return blocks
495
+ return blocks
496
496
 
497
497
 
498
498
  def _parse_extents(inode: INode, buf: bytes) -> Iterator[c_ext.ext4_extent]:
@@ -2,13 +2,16 @@ from __future__ import annotations
2
2
 
3
3
  import datetime
4
4
  import io
5
- from typing import BinaryIO, Iterator, Optional
5
+ from typing import TYPE_CHECKING, BinaryIO
6
6
 
7
7
  from dissect.util.stream import RangeStream
8
8
 
9
9
  from dissect.extfs.c_jdb2 import c_jdb2
10
10
  from dissect.extfs.exceptions import Error
11
11
 
12
+ if TYPE_CHECKING:
13
+ from collections.abc import Iterator
14
+
12
15
 
13
16
  class JDB2:
14
17
  def __init__(self, fh: BinaryIO):
@@ -132,7 +135,7 @@ class CommitBlock:
132
135
  jdb2: JDB2,
133
136
  header: c_jdb2.commit_header,
134
137
  journal_block: int,
135
- descriptors: Optional[list[DescriptorBlock]] = None,
138
+ descriptors: list[DescriptorBlock] | None = None,
136
139
  ):
137
140
  self.jdb2 = jdb2
138
141
  self.header = header
@@ -140,7 +143,7 @@ class CommitBlock:
140
143
  self.descriptors = descriptors if descriptors else []
141
144
 
142
145
  self.sequence = self.header.h_sequence
143
- self.ts = datetime.datetime.utcfromtimestamp(self.header.h_commit_sec)
146
+ self.ts = datetime.datetime.fromtimestamp(self.header.h_commit_sec, tz=datetime.timezone.utc)
144
147
  self.ts += datetime.timedelta(microseconds=self.header.h_commit_nsec // 1000)
145
148
 
146
149
  def __repr__(self) -> str:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dissect.extfs
3
- Version: 3.12
3
+ Version: 3.13.dev1
4
4
  Summary: A Dissect module implementing a parser for the ExtFS file system, the native filesystem for Linux operating systems
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -41,13 +41,56 @@ dev = [
41
41
  "dissect.util>=3.0.dev,<4.0.dev",
42
42
  ]
43
43
 
44
- [tool.black]
44
+ [tool.ruff]
45
45
  line-length = 120
46
+ required-version = ">=0.9.0"
46
47
 
47
- [tool.isort]
48
- profile = "black"
49
- known_first_party = ["dissect.extfs"]
50
- known_third_party = ["dissect"]
48
+ [tool.ruff.format]
49
+ docstring-code-format = true
50
+
51
+ [tool.ruff.lint]
52
+ select = [
53
+ "F",
54
+ "E",
55
+ "W",
56
+ "I",
57
+ "UP",
58
+ "YTT",
59
+ "ANN",
60
+ "B",
61
+ "C4",
62
+ "DTZ",
63
+ "T10",
64
+ "FA",
65
+ "ISC",
66
+ "G",
67
+ "INP",
68
+ "PIE",
69
+ "PYI",
70
+ "PT",
71
+ "Q",
72
+ "RSE",
73
+ "RET",
74
+ "SLOT",
75
+ "SIM",
76
+ "TID",
77
+ "TCH",
78
+ "PTH",
79
+ "PLC",
80
+ "TRY",
81
+ "FLY",
82
+ "PERF",
83
+ "FURB",
84
+ "RUF",
85
+ ]
86
+ ignore = ["E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "SIM105", "TRY003"]
87
+
88
+ [tool.ruff.lint.per-file-ignores]
89
+ "tests/docs/**" = ["INP001"]
90
+
91
+ [tool.ruff.lint.isort]
92
+ known-first-party = ["dissect.extfs"]
93
+ known-third-party = ["dissect"]
51
94
 
52
95
  [tool.setuptools]
53
96
  license-files = ["LICENSE", "COPYRIGHT"]
@@ -56,3 +99,4 @@ license-files = ["LICENSE", "COPYRIGHT"]
56
99
  include = ["dissect.*"]
57
100
 
58
101
  [tool.setuptools_scm]
102
+ local_scheme = "no-local-version"
@@ -1,15 +1,20 @@
1
+ from __future__ import annotations
2
+
1
3
  import gzip
2
- import os
3
- from typing import BinaryIO, Iterator
4
+ from pathlib import Path
5
+ from typing import TYPE_CHECKING, BinaryIO
4
6
 
5
7
  import pytest
6
8
 
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Iterator
11
+
7
12
 
8
- def absolute_path(filename) -> str:
9
- return os.path.join(os.path.dirname(__file__), filename)
13
+ def absolute_path(filename: str) -> Path:
14
+ return Path(__file__).parent / filename
10
15
 
11
16
 
12
- def gzip_file(filename) -> Iterator[BinaryIO]:
17
+ def gzip_file(filename: str) -> Iterator[BinaryIO]:
13
18
  with gzip.GzipFile(absolute_path(filename), "rb") as fh:
14
19
  yield fh
15
20
 
@@ -1,10 +1,12 @@
1
+ from __future__ import annotations
2
+
1
3
  import pytest
2
4
 
3
5
  from dissect.extfs import exceptions
4
6
 
5
7
 
6
8
  @pytest.mark.parametrize(
7
- "exc, std",
9
+ ("exc", "std"),
8
10
  [
9
11
  (exceptions.FileNotFoundError, FileNotFoundError),
10
12
  (exceptions.IsADirectoryError, IsADirectoryError),
@@ -1,9 +1,10 @@
1
+ from __future__ import annotations
2
+
1
3
  import datetime
2
4
  import gzip
3
5
  import stat
4
6
  from io import BytesIO
5
- from logging import Logger
6
- from typing import BinaryIO
7
+ from typing import TYPE_CHECKING, BinaryIO
7
8
  from unittest.mock import call, patch
8
9
 
9
10
  import pytest
@@ -11,8 +12,11 @@ import pytest
11
12
  from dissect.extfs.c_ext import c_ext
12
13
  from dissect.extfs.extfs import EXT4, ExtFS, INode
13
14
 
15
+ if TYPE_CHECKING:
16
+ from logging import Logger
17
+
14
18
 
15
- def test_ext4(ext4_bin: BinaryIO):
19
+ def test_ext4(ext4_bin: BinaryIO) -> None:
16
20
  extfs = ExtFS(ext4_bin)
17
21
 
18
22
  assert extfs.type == EXT4
@@ -43,7 +47,7 @@ def test_ext4(ext4_bin: BinaryIO):
43
47
  assert len(list(extfs.journal.commits())) == 2
44
48
 
45
49
 
46
- def test_xattr(ext4_bin: BinaryIO):
50
+ def test_xattr(ext4_bin: BinaryIO) -> None:
47
51
  e = ExtFS(ext4_bin)
48
52
 
49
53
  inode = e.get("xattr_cap")
@@ -56,7 +60,7 @@ def test_xattr(ext4_bin: BinaryIO):
56
60
  assert xattrs[1].value == b"\x01\x00\x00\x02\x00\x04@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
57
61
 
58
62
 
59
- def test_sparse(ext4_sparse_bin: BinaryIO):
63
+ def test_sparse(ext4_sparse_bin: BinaryIO) -> None:
60
64
  extfs = ExtFS(ext4_sparse_bin)
61
65
 
62
66
  sparse_start = extfs.get("sparse_start")
@@ -84,11 +88,11 @@ def test_sparse(ext4_sparse_bin: BinaryIO):
84
88
  ("tests/data/ext4_symlink_test3.bin.gz"),
85
89
  ],
86
90
  )
87
- def test_symlinks(image_file: str):
91
+ def test_symlinks(image_file: str) -> None:
88
92
  path = "/path/to/dir/with/file.ext"
89
93
  expect = b"resolved!\n"
90
94
 
91
- def resolve(node):
95
+ def resolve(node: INode) -> INode:
92
96
  while node.filetype == stat.S_IFLNK:
93
97
  node = node.link_inode
94
98
  return node
@@ -100,7 +104,7 @@ def test_symlinks(image_file: str):
100
104
  @patch("dissect.extfs.extfs.INode.open", return_value=BytesIO(b"\x00" * 16))
101
105
  @patch("dissect.extfs.extfs.log", create=True, return_value=None)
102
106
  @patch("dissect.extfs.extfs.ExtFS")
103
- def test_infinite_loop_protection(ExtFS: ExtFS, log: Logger, *args):
107
+ def test_infinite_loop_protection(ExtFS: ExtFS, log: Logger, *args) -> None:
104
108
  ExtFS.sb.s_inodes_count = 69
105
109
  ExtFS._dirtype = c_ext.ext2_dir_entry_2
106
110
  inode = INode(ExtFS, 1, filetype=stat.S_IFDIR)
@@ -32,23 +32,17 @@ commands =
32
32
  [testenv:fix]
33
33
  package = skip
34
34
  deps =
35
- black==23.1.0
36
- isort==5.11.4
35
+ ruff==0.9.2
37
36
  commands =
38
- black dissect tests
39
- isort dissect tests
37
+ ruff format dissect tests
40
38
 
41
39
  [testenv:lint]
42
40
  package = skip
43
41
  deps =
44
- black==23.1.0
45
- flake8
46
- flake8-black
47
- flake8-isort
48
- isort==5.11.4
42
+ ruff==0.9.2
49
43
  vermin
50
44
  commands =
51
- flake8 dissect tests
45
+ ruff check dissect tests
52
46
  vermin -t=3.9- --no-tips --lint dissect tests
53
47
 
54
48
  [flake8]
File without changes
@@ -8,11 +8,11 @@ from dissect.extfs.extfs import ExtFS, INode
8
8
  from dissect.extfs.journal import JDB2
9
9
 
10
10
  __all__ = [
11
- "ExtFS",
12
- "INode",
13
11
  "JDB2",
14
12
  "Error",
13
+ "ExtFS",
15
14
  "FileNotFoundError",
15
+ "INode",
16
16
  "NotADirectoryError",
17
17
  "NotASymlinkError",
18
18
  ]