1
1
# -*- coding: utf-8 -*-
2
2
"""The NTFS directory implementation."""
3
3
4
- from dfvfs .lib import errors
5
4
from dfvfs .path import ntfs_path_spec
6
5
from dfvfs .vfs import directory
7
6
@@ -11,6 +10,17 @@ class NTFSDirectory(directory.Directory):
11
10
12
11
_FILE_REFERENCE_MFT_ENTRY_BITMASK = 0xffffffffffff
13
12
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
+
14
24
def _EntriesGenerator (self ):
15
25
"""Retrieves directory entries.
16
26
@@ -20,33 +30,26 @@ def _EntriesGenerator(self):
20
30
Yields:
21
31
NTFSPathSpec: NTFS path specification.
22
32
"""
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 )
0 commit comments