Skip to content

Commit

Permalink
Changes to replace stat with attributes log2timeline#52
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Jun 26, 2017
1 parent c1bf266 commit 3d49d8b
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 84 deletions.
1 change: 0 additions & 1 deletion dfvfs/vfs/bde_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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
6 changes: 4 additions & 2 deletions dfvfs/vfs/compressed_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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):
Expand Down Expand Up @@ -54,10 +55,11 @@ def _GetStat(self):
Returns:
VFSStat: a stat object.
"""
stat_object = super(CompressedStreamFileEntry, self)._GetStat()
stat_object = vfs_stat.VFSStat()

if self._compressed_stream:
# File data stat information.
stat_object.size = self._compressed_stream.get_size()

stat_object.type = self._type

return stat_object
55 changes: 36 additions & 19 deletions dfvfs/vfs/encoded_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

Expand All @@ -12,37 +13,53 @@ class EncodedStreamFileEntry(root_only_file_entry.RootOnlyFileEntry):

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

try:
stat_object = vfs_stat.VFSStat()
super(EncodedStreamFileEntry, self).__init__(
resolver_context, file_system, path_spec, is_root=is_root,
is_virtual=is_virtual)
self._encoded_stream = encoded_stream
self._type = definitions.FILE_ENTRY_TYPE_FILE

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

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

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

return stat_object
57 changes: 37 additions & 20 deletions dfvfs/vfs/encrypted_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,63 @@

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(
u'Unable to open encrypted stream: {0:s}.'.format(
self.path_spec.comparable))
raise errors.BackEndError(u'Missing encrypted stream.')

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, u'_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
45 changes: 27 additions & 18 deletions dfvfs/vfs/fvde_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,48 @@
from dfvfs.lib import definitions
from dfvfs.lib import errors
from dfvfs.vfs import root_only_file_entry
from dfvfs.vfs import vfs_stat


class FVDEFileEntry(root_only_file_entry.RootOnlyFileEntry):
"""Class that implements a file entry object using FVDE."""
"""File system file entry that uses pyfvde."""

TYPE_INDICATOR = definitions.TYPE_INDICATOR_FVDE

def _GetStat(self):
"""Retrieves the stat object.
def __init__(
self, resolver_context, file_system, path_spec, is_root=False,
is_virtual=False):
"""Initializes the file entry object.
Returns:
VFSStat: stat object.
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 FVDE file is missing.
BackEndError: when the FVDE volume is missing.
entry emulated by the corresponding file system.
"""
fvde_volume = self._file_system.GetFVDEVolume()
fvde_volume = file_system.GetFVDEVolume()
if fvde_volume is None:
raise errors.BackEndError(u'Missing FVDE volume.')

stat_object = vfs_stat.VFSStat()

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

# Date and time stat information.
super(FVDEFileEntry, self).__init__(
resolver_context, file_system, path_spec, is_root=is_root,
is_virtual=is_virtual)
self._fvde_volume = fvde_volume
self._type = definitions.FILE_ENTRY_TYPE_FILE

# 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 = super(FVDEFileEntry, self)._GetStat()

# Other stat information.
stat_object.size = self._fvde_volume.get_size()

return stat_object
73 changes: 49 additions & 24 deletions dfvfs/vfs/gzip_file_entry.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,76 @@
# -*- coding: utf-8 -*-
"""The gzip file entry implementation."""

from dfdatetime import posix_time as dfdatetime_posix_time

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 GzipFileEntry(root_only_file_entry.RootOnlyFileEntry):
"""Class that implements a file entry object using gzip."""
"""File system file entry that uses gzip."""

TYPE_INDICATOR = definitions.TYPE_INDICATOR_GZIP

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 gzip file is missing.
"""
gzip_file = self.GetFileObject()
gzip_file = resolver.Resolver.OpenFileObject(
path_spec, resolver_context=resolver_context)
if not gzip_file:
raise errors.BackEndError(
u'Unable to open gzip file: {0:s}.'.format(self.path_spec.comparable))
raise errors.BackEndError(u'Missing gzip file.')

try:
stat_object = vfs_stat.VFSStat()
super(GzipFileEntry, self).__init__(
resolver_context, file_system, path_spec, is_root=is_root,
is_virtual=is_virtual)
self._gzip_file = gzip_file
self._type = definitions.FILE_ENTRY_TYPE_FILE

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

# Date and time stat information.
stat_object.mtime = gzip_file.modification_time
super(GzipFileEntry, 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 = super(GzipFileEntry, self)._GetStat()

# Other stat information.
# gzip_file.comment
# gzip_file.operating_system
# gzip_file.original_filename
if self._gzip_file:
stat_object.size = self._gzip_file.uncompressed_data_size

finally:
gzip_file.close()
# Other stat information.
# gzip_file.comment
# gzip_file.operating_system
# gzip_file.original_filename

return stat_object

@property
def modification_time(self):
"""dfdatetime.DateTimeValues: modification time or None if not available."""
timestamp = getattr(self._gzip_file, u'modification_time', None)
if timestamp is not None:
return dfdatetime_posix_time.PosixTime(timestamp=timestamp)

0 comments on commit 3d49d8b

Please sign in to comment.