forked from log2timeline/dfvfs
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to replace stat with attributes log2timeline#52
- Loading branch information
1 parent
c1bf266
commit 3d49d8b
Showing
6 changed files
with
153 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |