Skip to content

Commit afefcc6

Browse files
authored
Remove back-end resolve from directory (#658)
1 parent 4a84328 commit afefcc6

18 files changed

+135
-85
lines changed

config/dpkg/changelog

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
dfvfs (20220418-1) unstable; urgency=low
1+
dfvfs (20220419-1) unstable; urgency=low
22

33
* Auto-generated
44

5-
-- Log2Timeline maintainers <[email protected]> Mon, 18 Apr 2022 16:15:40 +0200
5+
-- Log2Timeline maintainers <[email protected]> Tue, 19 Apr 2022 11:17:49 +0200

dfvfs/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
storage media types and file formats.
77
"""
88

9-
__version__ = '20220418'
9+
__version__ = '20220419'

dfvfs/vfs/apfs_directory.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
# -*- coding: utf-8 -*-
22
"""The APFS directory implementation."""
33

4-
from dfvfs.lib import errors
54
from dfvfs.path import apfs_path_spec
65
from dfvfs.vfs import directory
76

87

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

11+
def __init__(self, file_system, path_spec, fsapfs_file_entry):
12+
"""Initializes a directory.
13+
14+
Args:
15+
file_system (FileSystem): file system.
16+
path_spec (PathSpec): path specification.
17+
fsapfs_file_entry (pyfsapfs.file_entry): APFS file entry.
18+
"""
19+
super(APFSDirectory, self).__init__(file_system, path_spec)
20+
self._fsapfs_file_entry = fsapfs_file_entry
21+
1222
def _EntriesGenerator(self):
1323
"""Retrieves directory entries.
1424
@@ -18,15 +28,9 @@ def _EntriesGenerator(self):
1828
Yields:
1929
APFSPathSpec: APFS path specification.
2030
"""
21-
try:
22-
fsapfs_file_entry = self._file_system.GetAPFSFileEntryByPathSpec(
23-
self.path_spec)
24-
except errors.PathSpecError:
25-
return
26-
2731
location = getattr(self.path_spec, 'location', None)
2832

29-
for fsapfs_sub_file_entry in fsapfs_file_entry.sub_file_entries:
33+
for fsapfs_sub_file_entry in self._fsapfs_file_entry.sub_file_entries:
3034
directory_entry = fsapfs_sub_file_entry.name
3135

3236
if not location or location == self._file_system.PATH_SEPARATOR:

dfvfs/vfs/apfs_file_entry.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def _GetDirectory(self):
8686
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
8787
return None
8888

89-
return apfs_directory.APFSDirectory(self._file_system, self.path_spec)
89+
return apfs_directory.APFSDirectory(
90+
self._file_system, self.path_spec, self._fsapfs_file_entry)
9091

9192
def _GetLink(self):
9293
"""Retrieves the link.

dfvfs/vfs/ext_directory.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
# -*- coding: utf-8 -*-
22
"""The EXT directory implementation."""
33

4-
from dfvfs.lib import errors
54
from dfvfs.path import ext_path_spec
65
from dfvfs.vfs import directory
76

87

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

11+
def __init__(self, file_system, path_spec, fsext_file_entry):
12+
"""Initializes a directory.
13+
14+
Args:
15+
file_system (FileSystem): file system.
16+
path_spec (PathSpec): path specification.
17+
fsext_file_entry (pyfsext.file_entry): EXT file entry.
18+
"""
19+
super(EXTDirectory, self).__init__(file_system, path_spec)
20+
self._fsext_file_entry = fsext_file_entry
21+
1222
def _EntriesGenerator(self):
1323
"""Retrieves directory entries.
1424
@@ -18,15 +28,9 @@ def _EntriesGenerator(self):
1828
Yields:
1929
EXTPathSpec: EXT path specification.
2030
"""
21-
try:
22-
fsext_file_entry = self._file_system.GetEXTFileEntryByPathSpec(
23-
self.path_spec)
24-
except errors.PathSpecError:
25-
return
26-
2731
location = getattr(self.path_spec, 'location', None)
2832

29-
for fsext_sub_file_entry in fsext_file_entry.sub_file_entries:
33+
for fsext_sub_file_entry in self._fsext_file_entry.sub_file_entries:
3034
directory_entry = fsext_sub_file_entry.name
3135

3236
if not location or location == self._file_system.PATH_SEPARATOR:

dfvfs/vfs/ext_file_entry.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def _GetDirectory(self):
103103
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
104104
return None
105105

106-
return ext_directory.EXTDirectory(self._file_system, self.path_spec)
106+
return ext_directory.EXTDirectory(
107+
self._file_system, self.path_spec, self._fsext_file_entry)
107108

108109
def _GetLink(self):
109110
"""Retrieves the link.

dfvfs/vfs/hfs_directory.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
# -*- coding: utf-8 -*-
22
"""The HFS directory implementation."""
33

4-
from dfvfs.lib import errors
54
from dfvfs.path import hfs_path_spec
65
from dfvfs.vfs import directory
76

87

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

11+
def __init__(self, file_system, path_spec, fshfs_file_entry):
12+
"""Initializes a directory.
13+
14+
Args:
15+
file_system (FileSystem): file system.
16+
path_spec (PathSpec): path specification.
17+
fshfs_file_entry (pyfshfs.file_entry): HFS file entry.
18+
"""
19+
super(HFSDirectory, self).__init__(file_system, path_spec)
20+
self._fshfs_file_entry = fshfs_file_entry
21+
1222
def _EntriesGenerator(self):
1323
"""Retrieves directory entries.
1424
@@ -18,15 +28,9 @@ def _EntriesGenerator(self):
1828
Yields:
1929
HFSPathSpec: HFS path specification.
2030
"""
21-
try:
22-
fshfs_file_entry = self._file_system.GetHFSFileEntryByPathSpec(
23-
self.path_spec)
24-
except errors.PathSpecError:
25-
return
26-
2731
location = getattr(self.path_spec, 'location', None)
2832

29-
for fshfs_sub_file_entry in fshfs_file_entry.sub_file_entries:
33+
for fshfs_sub_file_entry in self._fshfs_file_entry.sub_file_entries:
3034
directory_entry = fshfs_sub_file_entry.name
3135

3236
if not location or location == self._file_system.PATH_SEPARATOR:

dfvfs/vfs/hfs_file_entry.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def _GetDirectory(self):
117117
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
118118
return None
119119

120-
return hfs_directory.HFSDirectory(self._file_system, self.path_spec)
120+
return hfs_directory.HFSDirectory(
121+
self._file_system, self.path_spec, self._fshfs_file_entry)
121122

122123
def _GetLink(self):
123124
"""Retrieves the link.

dfvfs/vfs/ntfs_directory.py

+34-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""The NTFS directory implementation."""
33

4-
from dfvfs.lib import errors
54
from dfvfs.path import ntfs_path_spec
65
from dfvfs.vfs import directory
76

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

1211
_FILE_REFERENCE_MFT_ENTRY_BITMASK = 0xffffffffffff
1312

13+
def __init__(self, file_system, path_spec, fsntfs_file_entry):
14+
"""Initializes a directory.
15+
16+
Args:
17+
file_system (FileSystem): file system.
18+
path_spec (PathSpec): path specification.
19+
fsntfs_file_entry (pyfsntfs.file_entry): NTFS file entry.
20+
"""
21+
super(NTFSDirectory, self).__init__(file_system, path_spec)
22+
self._fsntfs_file_entry = fsntfs_file_entry
23+
1424
def _EntriesGenerator(self):
1525
"""Retrieves directory entries.
1626
@@ -20,33 +30,26 @@ def _EntriesGenerator(self):
2030
Yields:
2131
NTFSPathSpec: NTFS path specification.
2232
"""
23-
try:
24-
fsntfs_file_entry = self._file_system.GetNTFSFileEntryByPathSpec(
25-
self.path_spec)
26-
except errors.PathSpecError:
27-
fsntfs_file_entry = None
28-
29-
if fsntfs_file_entry:
30-
location = getattr(self.path_spec, 'location', None)
31-
32-
for fsntfs_sub_file_entry in fsntfs_file_entry.sub_file_entries:
33-
directory_entry = fsntfs_sub_file_entry.name
34-
35-
# Ignore references to self or parent.
36-
if directory_entry in ('.', '..'):
37-
continue
38-
39-
file_reference = fsntfs_sub_file_entry.file_reference
40-
directory_entry_mft_entry = (
41-
file_reference & self._FILE_REFERENCE_MFT_ENTRY_BITMASK)
42-
43-
if not location or location == self._file_system.PATH_SEPARATOR:
44-
directory_entry = self._file_system.JoinPath([directory_entry])
45-
else:
46-
directory_entry = self._file_system.JoinPath([
47-
location, directory_entry])
48-
49-
yield ntfs_path_spec.NTFSPathSpec(
50-
location=directory_entry,
51-
mft_attribute=fsntfs_sub_file_entry.name_attribute_index,
52-
mft_entry=directory_entry_mft_entry, parent=self.path_spec.parent)
33+
location = getattr(self.path_spec, 'location', None)
34+
35+
for fsntfs_sub_file_entry in self._fsntfs_file_entry.sub_file_entries:
36+
directory_entry = fsntfs_sub_file_entry.name
37+
38+
# Ignore references to self or parent.
39+
if directory_entry in ('.', '..'):
40+
continue
41+
42+
file_reference = fsntfs_sub_file_entry.file_reference
43+
directory_entry_mft_entry = (
44+
file_reference & self._FILE_REFERENCE_MFT_ENTRY_BITMASK)
45+
46+
if not location or location == self._file_system.PATH_SEPARATOR:
47+
directory_entry = self._file_system.JoinPath([directory_entry])
48+
else:
49+
directory_entry = self._file_system.JoinPath([
50+
location, directory_entry])
51+
52+
yield ntfs_path_spec.NTFSPathSpec(
53+
location=directory_entry,
54+
mft_attribute=fsntfs_sub_file_entry.name_attribute_index,
55+
mft_entry=directory_entry_mft_entry, parent=self.path_spec.parent)

dfvfs/vfs/ntfs_file_entry.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def _GetDirectory(self):
114114
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
115115
return None
116116

117-
return ntfs_directory.NTFSDirectory(self._file_system, self.path_spec)
117+
return ntfs_directory.NTFSDirectory(
118+
self._file_system, self.path_spec, self._fsntfs_file_entry)
118119

119120
def _GetLink(self):
120121
"""Retrieves the link.

dfvfs/vfs/sqlite_blob_directory.py

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ def _EntriesGenerator(self):
2626
2727
Yields:
2828
SQLiteBlobPathSpec: a path specification.
29-
30-
Raises:
31-
AccessError: if the access to list the directory was denied.
32-
BackEndError: if the directory could not be listed.
3329
"""
3430
table_name = getattr(self.path_spec, 'table_name', None)
3531
column_name = getattr(self.path_spec, 'column_name', None)

dfvfs/vfs/xfs_directory.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
# -*- coding: utf-8 -*-
22
"""The XFS directory implementation."""
33

4-
from dfvfs.lib import errors
54
from dfvfs.path import xfs_path_spec
65
from dfvfs.vfs import directory
76

87

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

11+
def __init__(self, file_system, path_spec, fsxfs_file_entry):
12+
"""Initializes a directory.
13+
14+
Args:
15+
file_system (FileSystem): file system.
16+
path_spec (PathSpec): path specification.
17+
fsxfs_file_entry (pyfsxfs.file_entry): XFS file entry.
18+
"""
19+
super(XFSDirectory, self).__init__(file_system, path_spec)
20+
self._fsxfs_file_entry = fsxfs_file_entry
21+
1222
def _EntriesGenerator(self):
1323
"""Retrieves directory entries.
1424
@@ -18,15 +28,9 @@ def _EntriesGenerator(self):
1828
Yields:
1929
XFSPathSpec: XFS path specification.
2030
"""
21-
try:
22-
fsxfs_file_entry = self._file_system.GetXFSFileEntryByPathSpec(
23-
self.path_spec)
24-
except errors.PathSpecError:
25-
return
26-
2731
location = getattr(self.path_spec, 'location', None)
2832

29-
for fsxfs_sub_file_entry in fsxfs_file_entry.sub_file_entries:
33+
for fsxfs_sub_file_entry in self._fsxfs_file_entry.sub_file_entries:
3034
directory_entry = fsxfs_sub_file_entry.name
3135

3236
if not location or location == self._file_system.PATH_SEPARATOR:

dfvfs/vfs/xfs_file_entry.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def _GetDirectory(self):
100100
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
101101
return None
102102

103-
return xfs_directory.XFSDirectory(self._file_system, self.path_spec)
103+
return xfs_directory.XFSDirectory(
104+
self._file_system, self.path_spec, self._fsxfs_file_entry)
104105

105106
def _GetLink(self):
106107
"""Retrieves the link.

tests/vfs/apfs_directory.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,21 @@ def tearDown(self):
4343

4444
def testInitialize(self):
4545
"""Tests the __init__ function."""
46+
fsapfs_file_entry = self._file_system.GetAPFSFileEntryByPathSpec(
47+
self._apfs_path_spec)
48+
4649
directory = apfs_directory.APFSDirectory(
47-
self._file_system, self._apfs_path_spec)
50+
self._file_system, self._apfs_path_spec, fsapfs_file_entry)
4851

4952
self.assertIsNotNone(directory)
5053

5154
def testEntriesGenerator(self):
5255
"""Tests the _EntriesGenerator function."""
56+
fsapfs_file_entry = self._file_system.GetAPFSFileEntryByPathSpec(
57+
self._apfs_path_spec)
58+
5359
directory = apfs_directory.APFSDirectory(
54-
self._file_system, self._apfs_path_spec)
60+
self._file_system, self._apfs_path_spec, fsapfs_file_entry)
5561

5662
self.assertIsNotNone(directory)
5763

tests/vfs/ext_directory.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,21 @@ def tearDown(self):
4040

4141
def testInitialize(self):
4242
"""Tests the __init__ function."""
43+
fsext_file_entry = self._file_system.GetEXTFileEntryByPathSpec(
44+
self._ext_path_spec)
45+
4346
directory = ext_directory.EXTDirectory(
44-
self._file_system, self._ext_path_spec)
47+
self._file_system, self._ext_path_spec, fsext_file_entry)
4548

4649
self.assertIsNotNone(directory)
4750

4851
def testEntriesGenerator(self):
4952
"""Tests the _EntriesGenerator function."""
53+
fsext_file_entry = self._file_system.GetEXTFileEntryByPathSpec(
54+
self._ext_path_spec)
55+
5056
directory = ext_directory.EXTDirectory(
51-
self._file_system, self._ext_path_spec)
57+
self._file_system, self._ext_path_spec, fsext_file_entry)
5258

5359
self.assertIsNotNone(directory)
5460

0 commit comments

Comments
 (0)