Index: dfvfs/vfs/encrypted_stream_file_entry.py |
diff --git a/dfvfs/vfs/encrypted_stream_file_entry.py b/dfvfs/vfs/encrypted_stream_file_entry.py |
index d283fe1509d061e986a5b7415753970d8e1b9b42..daf26e6183880608325c435018d0fac14914235a 100644 |
--- a/dfvfs/vfs/encrypted_stream_file_entry.py |
+++ b/dfvfs/vfs/encrypted_stream_file_entry.py |
@@ -5,46 +5,65 @@ from __future__ import unicode_literals |
from dfvfs.lib import definitions |
from dfvfs.lib import errors |
+from dfvfs.resolver import resolver |
from dfvfs.vfs import root_only_file_entry |
from dfvfs.vfs import vfs_stat |
class EncryptedStreamFileEntry(root_only_file_entry.RootOnlyFileEntry): |
- """Class that implements a encrypted stream file entry object.""" |
+ """Encrypted stream file entry.""" |
TYPE_INDICATOR = definitions.TYPE_INDICATOR_ENCRYPTED_STREAM |
- def _GetStat(self): |
- """Retrieves the stat object. |
+ def __init__( |
+ self, resolver_context, file_system, path_spec, is_root=False, |
+ is_virtual=False): |
+ """Initializes a file entry. |
- Returns: |
- The stat object (instance of vfs.VFSStat). |
+ Args: |
+ 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 |
Raises: |
BackEndError: when the encrypted stream is missing. |
""" |
- encrypted_stream = self.GetFileObject() |
+ encrypted_stream = resolver.Resolver.OpenFileObject( |
+ path_spec, resolver_context=resolver_context) |
if not encrypted_stream: |
raise errors.BackEndError( |
'Unable to open encrypted stream: {0:s}.'.format( |
self.path_spec.comparable)) |
- try: |
- stat_object = vfs_stat.VFSStat() |
+ super(EncryptedStreamFileEntry, self).__init__( |
+ resolver_context, file_system, path_spec, is_root=is_root, |
+ is_virtual=is_virtual) |
+ self._encrypted_stream = encrypted_stream |
+ self._type = definitions.FILE_ENTRY_TYPE_FILE |
- # File data stat information. |
- stat_object.size = encrypted_stream.get_size() |
+ def __del__(self): |
+ """Cleans up the file entry.""" |
+ # __del__ can be invoked before __init__ has completed. |
+ if hasattr(self, '_encrypted_stream'): |
+ self._encrypted_stream.close() |
+ self._encrypted_stream = None |
- # Date and time stat information. |
+ super(EncryptedStreamFileEntry, self).__del__() |
- # Ownership and permissions stat information. |
+ def _GetStat(self): |
+ """Retrieves information about the file entry. |
- # File entry type stat information. |
- stat_object.type = stat_object.TYPE_FILE |
+ Returns: |
+ VFSStat: a stat object. |
+ """ |
+ stat_object = vfs_stat.VFSStat() |
- # Other stat information. |
+ if self._encrypted_stream: |
+ stat_object.size = self._encrypted_stream.get_size() |
- finally: |
- encrypted_stream.close() |
+ stat_object.type = self._type |
return stat_object |