diff --git a/dfvfs/vfs/tsk_partition_file_entry.py b/dfvfs/vfs/tsk_partition_file_entry.py index fc1f2e5b..74ea8581 100644 --- a/dfvfs/vfs/tsk_partition_file_entry.py +++ b/dfvfs/vfs/tsk_partition_file_entry.py @@ -6,11 +6,10 @@ from dfvfs.lib import tsk_partition from dfvfs.path import tsk_partition_path_spec from dfvfs.vfs import file_entry -from dfvfs.vfs import vfs_stat class TSKPartitionDirectory(file_entry.Directory): - """Class that implements a directory object using pytsk3.""" + """File system directory that uses pytsk3.""" def _EntriesGenerator(self): """Retrieves directory entries. @@ -61,66 +60,73 @@ def _EntriesGenerator(self): class TSKPartitionFileEntry(file_entry.FileEntry): - """Class that implements a file entry object using pytsk3.""" + """File system file entry that uses pytsk3.""" TYPE_INDICATOR = definitions.TYPE_INDICATOR_TSK_PARTITION def __init__( self, resolver_context, file_system, path_spec, is_root=False, - is_virtual=False): - """Initializes the file entry object. + is_virtual=False, tsk_vs_part=None): + """Initializes a file entry. Args: - resolver_context: the resolver context (instance of resolver.Context). - file_system: the file system object (instance of FileSystem). - path_spec: the path specification (instance of PathSpec). - is_virtual: optional boolean value to indicate if the file entry is - a virtual file entry emulated by the corresponding file - system. + resolver_context (Context): resolver context. + file_system (FileSystem): file system. + path_spec (PathSpec): path specification. + is_root (Optional[bool]): True if the file entry is the root file entry + of the corresponding file system. + is_virtual (Optional[bool]): True if the file entry is a virtual file + entry emulated by the corresponding file system. + tsk_vs_part (Optional[]): + + Raises: + BackEndError: when the tsk volume system part is missing in a non-virtual + file entry. """ + tsk_volume = file_system.GetTSKVolume() + if not is_virtual and tsk_vs_part is None: + tsk_vs_part, _ = tsk_partition.GetTSKVsPartByPathSpec( + tsk_volume, path_spec) + if not is_virtual and tsk_vs_part is None: + raise errors.BackEndError( + u'Missing tsk volume system part in non-virtual file entry.') + super(TSKPartitionFileEntry, self).__init__( resolver_context, file_system, path_spec, is_root=is_root, is_virtual=is_virtual) self._name = None + self._tsk_volume = tsk_volume + self._tsk_vs_part = tsk_vs_part + + if is_virtual: + self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY + else: + self._type = definitions.FILE_ENTRY_TYPE_FILE def _GetDirectory(self): """Retrieves a directory. Returns: - A directory object (instance of Directory) or None. + TSKPartitionDirectory: a directory or None if not available. """ - if self._stat_object is None: - self._stat_object = self._GetStat() - - if (self._stat_object and - self._stat_object.type == self._stat_object.TYPE_DIRECTORY): + if self._type == definitions.FILE_ENTRY_TYPE_DIRECTORY: return TSKPartitionDirectory(self._file_system, self.path_spec) - return def _GetStat(self): """Retrieves the stat object. Returns: - The stat object (instance of vfs.VFSStat). - - Raises: - BackEndError: when the tsk volume system part is missing in a non-virtual - file entry. + VFSStat: stat object. """ - tsk_vs_part = self.GetTSKVsPart() - stat_object = vfs_stat.VFSStat() - - if not self._is_virtual and tsk_vs_part is None: - raise errors.BackEndError( - u'Missing tsk volume system part in non-virtual file entry.') + stat_object = super(TSKPartitionFileEntry, self)._GetStat() - tsk_volume = self._file_system.GetTSKVolume() - bytes_per_sector = tsk_partition.TSKVolumeGetBytesPerSector(tsk_volume) + bytes_per_sector = tsk_partition.TSKVolumeGetBytesPerSector( + self._tsk_volume) # File data stat information. - if tsk_vs_part is not None: + if self._tsk_vs_part is not None: number_of_sectors = tsk_partition.TSKVsPartGetNumberOfSectors( - tsk_vs_part) + self._tsk_vs_part) if number_of_sectors: stat_object.size = number_of_sectors * bytes_per_sector @@ -132,20 +138,15 @@ def _GetStat(self): # File entry type stat information. # The root file entry is virtual and should have type directory. - if self._is_virtual: - stat_object.type = stat_object.TYPE_DIRECTORY - else: - stat_object.type = stat_object.TYPE_FILE - if not self._is_virtual: stat_object.is_allocated = tsk_partition.TSKVsPartIsAllocated( - tsk_vs_part) + self._tsk_vs_part) return stat_object @property def name(self): - """The name of the file entry, which does not include the full path.""" + """str: name of the file entry, which does not include the full path.""" if self._name is None: # Directory entries without a location in the path specification # are not given a name for now. @@ -158,7 +159,7 @@ def name(self): @property def sub_file_entries(self): - """The sub file entries (generator of instance of vfs.FileEntry).""" + """generator(TSKPartitionFileEntry): sub file entries.""" if self._directory is None: self._directory = self._GetDirectory() @@ -171,19 +172,16 @@ def GetParentFileEntry(self): """Retrieves the parent file entry. Returns: - The parent file entry (instance of FileEntry) or None. + TSKPartitionFileEntry: parent file entry or None if not available. """ # TODO: implement https://github.com/log2timeline/dfvfs/issues/76. return def GetTSKVsPart(self): - """Retrieves the TSK volume system part object. + """Retrieves the TSK volume system part. Returns: - A TSK volume system part object (instance of pytsk3.TSK_VS_PART_INFO) - or None. + pytsk3.TSK_VS_PART_INFO: a TSK volume system part or None if not + available. """ - tsk_volume = self._file_system.GetTSKVolume() - tsk_vs_part, _ = tsk_partition.GetTSKVsPartByPathSpec( - tsk_volume, self.path_spec) - return tsk_vs_part + return self._tsk_vs_part diff --git a/tests/vfs/tsk_partition_file_entry.py b/tests/vfs/tsk_partition_file_entry.py index e0087a2f..10de8a29 100644 --- a/tests/vfs/tsk_partition_file_entry.py +++ b/tests/vfs/tsk_partition_file_entry.py @@ -52,7 +52,7 @@ def testIntialize(self): """Test the __init__ function.""" file_entry = tsk_partition_file_entry.TSKPartitionFileEntry( self._resolver_context, self._file_system, - self._tsk_partition_path_spec) + self._tsk_partition_path_spec, is_virtual=True) self.assertIsNotNone(file_entry)