def GetFileEntryByPathSpec(self, path_spec): """Retrieves a file entry for a path specification. Args: path_spec (PathSpec): path specification. Returns: NTFSFileEntry: file entry or None if not available. Raises: BackEndError: if the file entry cannot be opened. """ # Opening a file by MFT entry is faster than opening a file by location. # However we need the index of the corresponding $FILE_NAME MFT attribute. fsntfs_file_entry = None location = getattr(path_spec, 'location', None) mft_attribute = getattr(path_spec, 'mft_attribute', None) mft_entry = getattr(path_spec, 'mft_entry', None) if (location == self.LOCATION_ROOT or mft_entry == self.MFT_ENTRY_ROOT_DIRECTORY): fsntfs_file_entry = self._fsntfs_volume.get_root_directory() return ntfs_file_entry.NTFSFileEntry( self._resolver_context, self, path_spec, fsntfs_file_entry=fsntfs_file_entry, is_root=True) try: if mft_attribute is not None and mft_entry is not None: fsntfs_file_entry = self._fsntfs_volume.get_file_entry( mft_entry) elif location is not None: fsntfs_file_entry = self._fsntfs_volume.get_file_entry_by_path( location) except IOError as exception: raise errors.BackEndError(exception) if fsntfs_file_entry is None: return None return ntfs_file_entry.NTFSFileEntry( self._resolver_context, self, path_spec, fsntfs_file_entry=fsntfs_file_entry)
def testIntialize(self): """Tests the __init__ function.""" file_entry = ntfs_file_entry.NTFSFileEntry(self._resolver_context, self._file_system, self._ntfs_path_spec) self.assertIsNotNone(file_entry)