:py:mod:`dissect.target.helpers.fsutil` ======================================= .. py:module:: dissect.target.helpers.fsutil .. autoapi-nested-parse:: Filesystem and path related utilities. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: dissect.target.helpers.fsutil.stat_result Functions ~~~~~~~~~ .. autoapisummary:: :nosignatures: dissect.target.helpers.fsutil.abspath dissect.target.helpers.fsutil.basename dissect.target.helpers.fsutil.commonpath dissect.target.helpers.fsutil.dirname dissect.target.helpers.fsutil.isabs dissect.target.helpers.fsutil.join dissect.target.helpers.fsutil.normalize dissect.target.helpers.fsutil.normpath dissect.target.helpers.fsutil.relpath dissect.target.helpers.fsutil.split dissect.target.helpers.fsutil.splitroot dissect.target.helpers.fsutil.generate_addr dissect.target.helpers.fsutil.walk dissect.target.helpers.fsutil.walk_ext dissect.target.helpers.fsutil.glob_split dissect.target.helpers.fsutil.glob_ext dissect.target.helpers.fsutil.has_glob_magic dissect.target.helpers.fsutil.resolve_link dissect.target.helpers.fsutil.open_decompress dissect.target.helpers.fsutil.reverse_readlines dissect.target.helpers.fsutil.fs_attrs Attributes ~~~~~~~~~~ .. autoapisummary:: dissect.target.helpers.fsutil.splitdrive dissect.target.helpers.fsutil.splitext .. py:function:: abspath(path: str, cwd: str = '', alt_separator: str = '') -> str .. py:function:: basename(path: str, alt_separator: str = '') -> str .. py:function:: commonpath(paths: list[str], alt_separator: str = '') -> str .. py:function:: dirname(path: str, alt_separator: str = '') -> str .. py:function:: isabs(path: str, alt_separator: str = '') -> bool .. py:function:: join(*args, alt_separator: str = '') -> str .. py:function:: normalize(path: str, alt_separator: str = '') -> str .. py:function:: normpath(path: str, alt_separator: str = '') -> str .. py:function:: relpath(path: str, start: str, alt_separator: str = '') -> str .. py:function:: split(path: str, alt_separator: str = '') -> str .. py:data:: splitdrive .. py:data:: splitext .. py:function:: splitroot(path: str, alt_separator: str = '') -> tuple[str, str] .. py:function:: generate_addr(path: Union[str, pathlib.Path], alt_separator: str = '') -> int .. py:class:: stat_result(s: Sequence[Any]) Custom stat_result object, designed to mimick os.stat_result. The real stat_result is a CPython internal StructSeq, which kind of behaves like a namedtuple on steroids. We try to emulate some of that behaviour here. For consistency this class is also called stat_result. .. py:attribute:: __slots__ .. py:method:: __eq__(other) -> bool Return self==value. .. py:method:: __ne__(other) -> bool Return self!=value. .. py:method:: __getitem__(item) -> int .. py:method:: __iter__() -> Iterator[int] .. py:method:: __repr__() -> str Return repr(self). .. py:method:: copy(other) -> stat_result :classmethod: .. py:function:: walk(path_entry, topdown=True, onerror=None, followlinks=False) .. py:function:: walk_ext(path_entry, topdown=True, onerror=None, followlinks=False) .. py:function:: glob_split(pattern: str, alt_separator: str = '') -> tuple[str, str] Split a pattern on path part boundaries on the first path part with a glob pattern. :param pattern: A glob pattern to match names of filesystem entries against. :param alt_separator: An optional alternative path separator in use by the filesystem being matched. :returns: A tuple of a string with path parts up to the first path part that has a glob pattern and a string of the remaining path parts. .. py:function:: glob_ext(direntry: dissect.target.filesystem.FilesystemEntry, pattern: str) -> Iterator[dissect.target.filesystem.FilesystemEntry] Recursively search and return filesystem entries matching a given glob pattern. :param direntry: The filesystem entry relative to which to search. :param pattern: A glob pattern to match names of filesystem entries against. :Yields: Matching filesystem entries (files and/or directories). .. py:function:: has_glob_magic(s) -> bool .. py:function:: resolve_link(fs: dissect.target.filesystem.Filesystem, entry: dissect.target.filesystem.FilesystemEntry, previous_links: set[str] = None) -> dissect.target.filesystem.FilesystemEntry Resolves a symlink to its actual path. It stops resolving once it detects an infinite recursion loop. .. py:function:: open_decompress(path: Optional[dissect.target.helpers.compat.path_312.TargetPath] = None, mode: str = 'rb', *, fileobj: Optional[BinaryIO] = None, encoding: Optional[str] = 'UTF-8', errors: Optional[str] = 'backslashreplace', newline: Optional[str] = None) -> Union[BinaryIO, TextIO] Open and decompress a file. Handles gz, bz2 and zstd files. Uncompressed files are opened as-is. When passing in an already opened ``fileobj``, the mode, encoding, errors and newline arguments are ignored. :param path: The path to the file to open and decompress. It is assumed this path exists. :param mode: The mode in which to open the file. :param fileobj: The file-like object to open and decompress. This is mutually exclusive with path. :param encoding: The decoding for text streams. By default UTF-8 encoding is used. :param errors: The error handling for text streams. By default we're more lenient and use ``backslashreplace``. :param newline: How newlines are handled for text streams. :returns: An binary or text IO stream, depending on the mode with which the file was opened. .. rubric:: Example bytes_buf = open_decompress(Path("/dir/file.gz")).read() for line in open_decompress(Path("/dir/file.gz"), "rt"): print(line) .. py:function:: reverse_readlines(fh: TextIO, chunk_size: int = 1024 * 1024 * 8) -> Iterator[str] Like iterating over a ``TextIO`` file-like object, but starting from the end of the file. :param fh: The file-like object (opened in text mode) to iterate lines from. :param chunk_size: The chunk size to use for iterating over lines. :returns: An iterator of lines from the file-like object, in reverse. .. py:function:: fs_attrs(path: Union[os.PathLike, str, bytes], follow_symlinks: bool = True) -> dict[Union[os.PathLike, str, bytes], bytes] Return the extended attributes for a given path on the local filesystem. This is currently only implemented for Linux using os.listxattr and related functions. :param path: The path to get the extended attributes for. :param follow_symlinks: Wether to follow the symlink if the given path is a symlink. :returns: A dict containing the attribute names as keys and their values.