Skip to content

Commit c82f129

Browse files
committed
Handle fast symlinks
1 parent f63407c commit c82f129

10 files changed

Lines changed: 11 additions & 10 deletions

File tree

ext4/block.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportImportCycles=false
21
import errno
32
import io
43
import os

ext4/blockdescriptor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportImportCycles=false
21
from ctypes import (
32
c_uint16,
43
c_uint32,

ext4/directory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportImportCycles=false
21
from ctypes import (
32
addressof,
43
c_char,

ext4/enum.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportImportCycles=false
21
from ctypes import (
32
c_uint8,
43
c_uint16,

ext4/extent.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportImportCycles=false
21
from collections.abc import Iterator
32
from ctypes import (
43
c_uint16,

ext4/htree.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportImportCycles=false
21
import warnings
32
from collections.abc import Generator
43
from ctypes import (

ext4/inode.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportImportCycles=false
21
from __future__ import annotations
32

43
import errno
@@ -482,8 +481,17 @@ def open(
482481

483482

484483
class SymbolicLink(Inode):
484+
@property
485+
def is_fast_symlink(self) -> bool:
486+
i_blocks_lo = assert_cast(self.i_blocks_lo, int) # pyright: ignore[reportAny]
487+
return i_blocks_lo == 0 and not self.is_inline
488+
485489
def readlink(self) -> bytes:
486-
return self._open().read()
490+
if not self.is_fast_symlink:
491+
return self._open().read()
492+
493+
_ = self.volume.seek(self.offset + Inode.i_block.offset)
494+
return self.volume.read(self.i_size)
487495

488496

489497
class Directory(Inode):

ext4/struct.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportImportCycles=false
21
import ctypes
32
import errno
43
import warnings

ext4/superblock.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportImportCycles=false
21
from ctypes import (
32
c_ubyte,
43
c_uint8,

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,4 @@ ignore = [
9191
[tool.pyright]
9292
exclude = [".venv", "build"]
9393
reportMissingTypeStubs = false
94+
reportImportCycles = false

0 commit comments

Comments
 (0)