Skip to content

Commit

Permalink
Remove back-end resolve from directory (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Apr 19, 2022
1 parent 4a84328 commit afefcc6
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 85 deletions.
4 changes: 2 additions & 2 deletions config/dpkg/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dfvfs (20220418-1) unstable; urgency=low
dfvfs (20220419-1) unstable; urgency=low

* Auto-generated

-- Log2Timeline maintainers <[email protected]> Mon, 18 Apr 2022 16:15:40 +0200
-- Log2Timeline maintainers <[email protected]> Tue, 19 Apr 2022 11:17:49 +0200
2 changes: 1 addition & 1 deletion dfvfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
storage media types and file formats.
"""

__version__ = '20220418'
__version__ = '20220419'
20 changes: 12 additions & 8 deletions dfvfs/vfs/apfs_directory.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# -*- coding: utf-8 -*-
"""The APFS directory implementation."""

from dfvfs.lib import errors
from dfvfs.path import apfs_path_spec
from dfvfs.vfs import directory


class APFSDirectory(directory.Directory):
"""File system directory that uses pyfsapfs."""

def __init__(self, file_system, path_spec, fsapfs_file_entry):
"""Initializes a directory.
Args:
file_system (FileSystem): file system.
path_spec (PathSpec): path specification.
fsapfs_file_entry (pyfsapfs.file_entry): APFS file entry.
"""
super(APFSDirectory, self).__init__(file_system, path_spec)
self._fsapfs_file_entry = fsapfs_file_entry

def _EntriesGenerator(self):
"""Retrieves directory entries.
Expand All @@ -18,15 +28,9 @@ def _EntriesGenerator(self):
Yields:
APFSPathSpec: APFS path specification.
"""
try:
fsapfs_file_entry = self._file_system.GetAPFSFileEntryByPathSpec(
self.path_spec)
except errors.PathSpecError:
return

location = getattr(self.path_spec, 'location', None)

for fsapfs_sub_file_entry in fsapfs_file_entry.sub_file_entries:
for fsapfs_sub_file_entry in self._fsapfs_file_entry.sub_file_entries:
directory_entry = fsapfs_sub_file_entry.name

if not location or location == self._file_system.PATH_SEPARATOR:
Expand Down
3 changes: 2 additions & 1 deletion dfvfs/vfs/apfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def _GetDirectory(self):
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
return None

return apfs_directory.APFSDirectory(self._file_system, self.path_spec)
return apfs_directory.APFSDirectory(
self._file_system, self.path_spec, self._fsapfs_file_entry)

def _GetLink(self):
"""Retrieves the link.
Expand Down
20 changes: 12 additions & 8 deletions dfvfs/vfs/ext_directory.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# -*- coding: utf-8 -*-
"""The EXT directory implementation."""

from dfvfs.lib import errors
from dfvfs.path import ext_path_spec
from dfvfs.vfs import directory


class EXTDirectory(directory.Directory):
"""File system directory that uses pyfsext."""

def __init__(self, file_system, path_spec, fsext_file_entry):
"""Initializes a directory.
Args:
file_system (FileSystem): file system.
path_spec (PathSpec): path specification.
fsext_file_entry (pyfsext.file_entry): EXT file entry.
"""
super(EXTDirectory, self).__init__(file_system, path_spec)
self._fsext_file_entry = fsext_file_entry

def _EntriesGenerator(self):
"""Retrieves directory entries.
Expand All @@ -18,15 +28,9 @@ def _EntriesGenerator(self):
Yields:
EXTPathSpec: EXT path specification.
"""
try:
fsext_file_entry = self._file_system.GetEXTFileEntryByPathSpec(
self.path_spec)
except errors.PathSpecError:
return

location = getattr(self.path_spec, 'location', None)

for fsext_sub_file_entry in fsext_file_entry.sub_file_entries:
for fsext_sub_file_entry in self._fsext_file_entry.sub_file_entries:
directory_entry = fsext_sub_file_entry.name

if not location or location == self._file_system.PATH_SEPARATOR:
Expand Down
3 changes: 2 additions & 1 deletion dfvfs/vfs/ext_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def _GetDirectory(self):
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
return None

return ext_directory.EXTDirectory(self._file_system, self.path_spec)
return ext_directory.EXTDirectory(
self._file_system, self.path_spec, self._fsext_file_entry)

def _GetLink(self):
"""Retrieves the link.
Expand Down
20 changes: 12 additions & 8 deletions dfvfs/vfs/hfs_directory.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# -*- coding: utf-8 -*-
"""The HFS directory implementation."""

from dfvfs.lib import errors
from dfvfs.path import hfs_path_spec
from dfvfs.vfs import directory


class HFSDirectory(directory.Directory):
"""File system directory that uses pyfshfs."""

def __init__(self, file_system, path_spec, fshfs_file_entry):
"""Initializes a directory.
Args:
file_system (FileSystem): file system.
path_spec (PathSpec): path specification.
fshfs_file_entry (pyfshfs.file_entry): HFS file entry.
"""
super(HFSDirectory, self).__init__(file_system, path_spec)
self._fshfs_file_entry = fshfs_file_entry

def _EntriesGenerator(self):
"""Retrieves directory entries.
Expand All @@ -18,15 +28,9 @@ def _EntriesGenerator(self):
Yields:
HFSPathSpec: HFS path specification.
"""
try:
fshfs_file_entry = self._file_system.GetHFSFileEntryByPathSpec(
self.path_spec)
except errors.PathSpecError:
return

location = getattr(self.path_spec, 'location', None)

for fshfs_sub_file_entry in fshfs_file_entry.sub_file_entries:
for fshfs_sub_file_entry in self._fshfs_file_entry.sub_file_entries:
directory_entry = fshfs_sub_file_entry.name

if not location or location == self._file_system.PATH_SEPARATOR:
Expand Down
3 changes: 2 additions & 1 deletion dfvfs/vfs/hfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def _GetDirectory(self):
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
return None

return hfs_directory.HFSDirectory(self._file_system, self.path_spec)
return hfs_directory.HFSDirectory(
self._file_system, self.path_spec, self._fshfs_file_entry)

def _GetLink(self):
"""Retrieves the link.
Expand Down
65 changes: 34 additions & 31 deletions dfvfs/vfs/ntfs_directory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""The NTFS directory implementation."""

from dfvfs.lib import errors
from dfvfs.path import ntfs_path_spec
from dfvfs.vfs import directory

Expand All @@ -11,6 +10,17 @@ class NTFSDirectory(directory.Directory):

_FILE_REFERENCE_MFT_ENTRY_BITMASK = 0xffffffffffff

def __init__(self, file_system, path_spec, fsntfs_file_entry):
"""Initializes a directory.
Args:
file_system (FileSystem): file system.
path_spec (PathSpec): path specification.
fsntfs_file_entry (pyfsntfs.file_entry): NTFS file entry.
"""
super(NTFSDirectory, self).__init__(file_system, path_spec)
self._fsntfs_file_entry = fsntfs_file_entry

def _EntriesGenerator(self):
"""Retrieves directory entries.
Expand All @@ -20,33 +30,26 @@ def _EntriesGenerator(self):
Yields:
NTFSPathSpec: NTFS path specification.
"""
try:
fsntfs_file_entry = self._file_system.GetNTFSFileEntryByPathSpec(
self.path_spec)
except errors.PathSpecError:
fsntfs_file_entry = None

if fsntfs_file_entry:
location = getattr(self.path_spec, 'location', None)

for fsntfs_sub_file_entry in fsntfs_file_entry.sub_file_entries:
directory_entry = fsntfs_sub_file_entry.name

# Ignore references to self or parent.
if directory_entry in ('.', '..'):
continue

file_reference = fsntfs_sub_file_entry.file_reference
directory_entry_mft_entry = (
file_reference & self._FILE_REFERENCE_MFT_ENTRY_BITMASK)

if not location or location == self._file_system.PATH_SEPARATOR:
directory_entry = self._file_system.JoinPath([directory_entry])
else:
directory_entry = self._file_system.JoinPath([
location, directory_entry])

yield ntfs_path_spec.NTFSPathSpec(
location=directory_entry,
mft_attribute=fsntfs_sub_file_entry.name_attribute_index,
mft_entry=directory_entry_mft_entry, parent=self.path_spec.parent)
location = getattr(self.path_spec, 'location', None)

for fsntfs_sub_file_entry in self._fsntfs_file_entry.sub_file_entries:
directory_entry = fsntfs_sub_file_entry.name

# Ignore references to self or parent.
if directory_entry in ('.', '..'):
continue

file_reference = fsntfs_sub_file_entry.file_reference
directory_entry_mft_entry = (
file_reference & self._FILE_REFERENCE_MFT_ENTRY_BITMASK)

if not location or location == self._file_system.PATH_SEPARATOR:
directory_entry = self._file_system.JoinPath([directory_entry])
else:
directory_entry = self._file_system.JoinPath([
location, directory_entry])

yield ntfs_path_spec.NTFSPathSpec(
location=directory_entry,
mft_attribute=fsntfs_sub_file_entry.name_attribute_index,
mft_entry=directory_entry_mft_entry, parent=self.path_spec.parent)
3 changes: 2 additions & 1 deletion dfvfs/vfs/ntfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def _GetDirectory(self):
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
return None

return ntfs_directory.NTFSDirectory(self._file_system, self.path_spec)
return ntfs_directory.NTFSDirectory(
self._file_system, self.path_spec, self._fsntfs_file_entry)

def _GetLink(self):
"""Retrieves the link.
Expand Down
4 changes: 0 additions & 4 deletions dfvfs/vfs/sqlite_blob_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def _EntriesGenerator(self):
Yields:
SQLiteBlobPathSpec: a path specification.
Raises:
AccessError: if the access to list the directory was denied.
BackEndError: if the directory could not be listed.
"""
table_name = getattr(self.path_spec, 'table_name', None)
column_name = getattr(self.path_spec, 'column_name', None)
Expand Down
20 changes: 12 additions & 8 deletions dfvfs/vfs/xfs_directory.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# -*- coding: utf-8 -*-
"""The XFS directory implementation."""

from dfvfs.lib import errors
from dfvfs.path import xfs_path_spec
from dfvfs.vfs import directory


class XFSDirectory(directory.Directory):
"""File system directory that uses pyfsxfs."""

def __init__(self, file_system, path_spec, fsxfs_file_entry):
"""Initializes a directory.
Args:
file_system (FileSystem): file system.
path_spec (PathSpec): path specification.
fsxfs_file_entry (pyfsxfs.file_entry): XFS file entry.
"""
super(XFSDirectory, self).__init__(file_system, path_spec)
self._fsxfs_file_entry = fsxfs_file_entry

def _EntriesGenerator(self):
"""Retrieves directory entries.
Expand All @@ -18,15 +28,9 @@ def _EntriesGenerator(self):
Yields:
XFSPathSpec: XFS path specification.
"""
try:
fsxfs_file_entry = self._file_system.GetXFSFileEntryByPathSpec(
self.path_spec)
except errors.PathSpecError:
return

location = getattr(self.path_spec, 'location', None)

for fsxfs_sub_file_entry in fsxfs_file_entry.sub_file_entries:
for fsxfs_sub_file_entry in self._fsxfs_file_entry.sub_file_entries:
directory_entry = fsxfs_sub_file_entry.name

if not location or location == self._file_system.PATH_SEPARATOR:
Expand Down
3 changes: 2 additions & 1 deletion dfvfs/vfs/xfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def _GetDirectory(self):
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
return None

return xfs_directory.XFSDirectory(self._file_system, self.path_spec)
return xfs_directory.XFSDirectory(
self._file_system, self.path_spec, self._fsxfs_file_entry)

def _GetLink(self):
"""Retrieves the link.
Expand Down
10 changes: 8 additions & 2 deletions tests/vfs/apfs_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,21 @@ def tearDown(self):

def testInitialize(self):
"""Tests the __init__ function."""
fsapfs_file_entry = self._file_system.GetAPFSFileEntryByPathSpec(
self._apfs_path_spec)

directory = apfs_directory.APFSDirectory(
self._file_system, self._apfs_path_spec)
self._file_system, self._apfs_path_spec, fsapfs_file_entry)

self.assertIsNotNone(directory)

def testEntriesGenerator(self):
"""Tests the _EntriesGenerator function."""
fsapfs_file_entry = self._file_system.GetAPFSFileEntryByPathSpec(
self._apfs_path_spec)

directory = apfs_directory.APFSDirectory(
self._file_system, self._apfs_path_spec)
self._file_system, self._apfs_path_spec, fsapfs_file_entry)

self.assertIsNotNone(directory)

Expand Down
10 changes: 8 additions & 2 deletions tests/vfs/ext_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ def tearDown(self):

def testInitialize(self):
"""Tests the __init__ function."""
fsext_file_entry = self._file_system.GetEXTFileEntryByPathSpec(
self._ext_path_spec)

directory = ext_directory.EXTDirectory(
self._file_system, self._ext_path_spec)
self._file_system, self._ext_path_spec, fsext_file_entry)

self.assertIsNotNone(directory)

def testEntriesGenerator(self):
"""Tests the _EntriesGenerator function."""
fsext_file_entry = self._file_system.GetEXTFileEntryByPathSpec(
self._ext_path_spec)

directory = ext_directory.EXTDirectory(
self._file_system, self._ext_path_spec)
self._file_system, self._ext_path_spec, fsext_file_entry)

self.assertIsNotNone(directory)

Expand Down
Loading

0 comments on commit afefcc6

Please sign in to comment.