Skip to content

Commit

Permalink
Code review: 320710043: Changes to replace stat with attributes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Jul 19, 2017
1 parent 881e154 commit d5a211f
Show file tree
Hide file tree
Showing 26 changed files with 921 additions and 711 deletions.
2 changes: 1 addition & 1 deletion config/dpkg/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ dfvfs (20170719-1) unstable; urgency=low

* Auto-generated

-- Log2Timeline <log2timeline-dev@googlegroups.com> Wed, 19 Jul 2017 17:37:42 +0200
-- Log2Timeline <log2timeline-dev@googlegroups.com> Wed, 19 Jul 2017 17:41:35 +0200
1 change: 0 additions & 1 deletion dfvfs/vfs/bde_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def _GetStat(self):
"""
stat_object = super(BDEFileEntry, self)._GetStat()

# File data stat information.
stat_object.size = self._bde_volume.get_size()

return stat_object
Expand Down
53 changes: 36 additions & 17 deletions dfvfs/vfs/compressed_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,65 @@

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 CompressedStreamFileEntry(root_only_file_entry.RootOnlyFileEntry):
"""Class that implements a compressed stream file entry object."""
"""Compressed stream file entry."""

TYPE_INDICATOR = definitions.TYPE_INDICATOR_COMPRESSED_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 compressed stream is missing.
"""
compressed_stream = self.GetFileObject()
compressed_stream = resolver.Resolver.OpenFileObject(
path_spec, resolver_context=resolver_context)
if not compressed_stream:
raise errors.BackEndError(
'Unable to open compressed stream: {0:s}.'.format(
self.path_spec.comparable))

try:
stat_object = vfs_stat.VFSStat()
super(CompressedStreamFileEntry, self).__init__(
resolver_context, file_system, path_spec, is_root=is_root,
is_virtual=is_virtual)
self._compressed_stream = compressed_stream
self._type = definitions.FILE_ENTRY_TYPE_FILE

# File data stat information.
stat_object.size = compressed_stream.get_size()
def __del__(self):
"""Cleans up the file entry."""
# __del__ can be invoked before __init__ has completed.
if hasattr(self, '_compressed_stream'):
self._compressed_stream.close()
self._compressed_stream = None

# Date and time stat information.
super(CompressedStreamFileEntry, 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._compressed_stream:
stat_object.size = self._compressed_stream.get_size()

finally:
compressed_stream.close()
stat_object.type = self._type

return stat_object
Loading

0 comments on commit d5a211f

Please sign in to comment.