Skip to content

Commit

Permalink
Preparations to remove stat object
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Aug 19, 2020
1 parent 552d66b commit 99aae01
Show file tree
Hide file tree
Showing 43 changed files with 1,567 additions and 437 deletions.
31 changes: 10 additions & 21 deletions dfvfs/vfs/apfs_container_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,6 @@ def _GetDirectory(self):

return self._directory

def _GetStat(self):
"""Retrieves information about the file entry.
Returns:
VFSStat: a stat object.
"""
stat_object = super(APFSContainerFileEntry, self)._GetStat()

if self._fsapfs_volume is not None:
# File data stat information.
# TODO: implement volume size.
# stat_object.size = self._fsapfs_volume.size
pass

# Ownership and permissions stat information.

# File entry type stat information.

# The root file entry is virtual and should have type directory.
return stat_object

def _GetSubFileEntries(self):
"""Retrieves a sub file entries generator.
Expand Down Expand Up @@ -140,8 +119,18 @@ def name(self):
self._name = 'apfs{0:d}'.format(volume_index + 1)
else:
self._name = ''

return self._name

@property
def size(self):
"""int: size of the file entry in bytes or None if not available."""
if self._fsapfs_volume is None:
return None

# TODO: change libfsapfs so self._fsapfs_volume.size works
return 0

@property
def sub_file_entries(self):
"""generator[APFSContainerFileEntry]: sub file entries."""
Expand Down
21 changes: 9 additions & 12 deletions dfvfs/vfs/apfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,15 @@ def _GetStat(self):
"""
stat_object = super(APFSFileEntry, self)._GetStat()

# File data stat information.
stat_object.size = self._fsapfs_file_entry.size

# Ownership and permissions stat information.
stat_object.mode = self._fsapfs_file_entry.file_mode & 0x0fff
stat_object.uid = self._fsapfs_file_entry.owner_identifier
stat_object.gid = self._fsapfs_file_entry.group_identifier

# File entry type stat information.
stat_object.type = self.entry_type

# Other stat information.
stat_object.ino = self._fsapfs_file_entry.identifier
stat_object.fs_type = 'APFS'

stat_object.is_allocated = True

return stat_object

def _GetSubFileEntries(self):
Expand Down Expand Up @@ -174,6 +166,12 @@ def creation_time(self):
timestamp = self._fsapfs_file_entry.get_creation_time_as_integer()
return dfdatetime_apfs_time.APFSTime(timestamp=timestamp)

@property
def modification_time(self):
"""dfdatetime.DateTimeValues: modification time or None if not available."""
timestamp = self._fsapfs_file_entry.get_modification_time_as_integer()
return dfdatetime_apfs_time.APFSTime(timestamp=timestamp)

@property
def name(self):
"""str: name of the file entry, which does not include the full path."""
Expand All @@ -184,10 +182,9 @@ def name(self):
return self._fsapfs_file_entry.name

@property
def modification_time(self):
"""dfdatetime.DateTimeValues: modification time or None if not available."""
timestamp = self._fsapfs_file_entry.get_modification_time_as_integer()
return dfdatetime_apfs_time.APFSTime(timestamp=timestamp)
def size(self):
"""int: size of the file entry in bytes or None if not available."""
return self._fsapfs_file_entry.size

def GetAPFSFileEntry(self):
"""Retrieves the APFS file entry.
Expand Down
17 changes: 5 additions & 12 deletions dfvfs/vfs/bde_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,13 @@ def __init__(
self._bde_volume = bde_volume
self.entry_type = definitions.FILE_ENTRY_TYPE_FILE

def _GetStat(self):
"""Retrieves information about the file entry.
Returns:
VFSStat: a stat object.
"""
stat_object = super(BDEFileEntry, self)._GetStat()

stat_object.size = self._bde_volume.get_size()

return stat_object

@property
def creation_time(self):
"""dfdatetime.DateTimeValues: creation time or None if not available."""
timestamp = self._bde_volume.get_creation_time_as_integer()
return dfdatetime_filetime.Filetime(timestamp=timestamp)

@property
def size(self):
"""int: size of the file entry in bytes or None if not available."""
return self._bde_volume.get_size()
19 changes: 4 additions & 15 deletions dfvfs/vfs/compressed_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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 @@ -53,17 +52,7 @@ def __del__(self):

super(CompressedStreamFileEntry, self).__del__()

def _GetStat(self):
"""Retrieves information about the file entry.
Returns:
VFSStat: a stat object.
"""
stat_object = vfs_stat.VFSStat()

if self._compressed_stream:
stat_object.size = self._compressed_stream.get_size()

stat_object.type = self.entry_type

return stat_object
@property
def size(self):
"""int: size of the file entry in bytes or None if not available."""
return self._compressed_stream.get_size()
9 changes: 5 additions & 4 deletions dfvfs/vfs/cpio_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ def _GetStat(self):
"""
stat_object = super(CPIOFileEntry, self)._GetStat()

# File data stat information.
stat_object.size = getattr(
self._cpio_archive_file_entry, 'data_size', None)

# Ownership and permissions stat information.
mode = getattr(self._cpio_archive_file_entry, 'mode', 0)
stat_object.mode = stat.S_IMODE(mode)
Expand Down Expand Up @@ -186,6 +182,11 @@ def modification_time(self):
return None
return dfdatetime_posix_time.PosixTime(timestamp=timestamp)

@property
def size(self):
"""int: size of the file entry in bytes or None if not available."""
return getattr(self._cpio_archive_file_entry, 'data_size', None)

def GetCPIOArchiveFileEntry(self):
"""Retrieves the CPIO archive file entry object.
Expand Down
23 changes: 4 additions & 19 deletions dfvfs/vfs/data_range_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from dfvfs.lib import definitions
from dfvfs.vfs import root_only_file_entry
from dfvfs.vfs import vfs_stat


class DataRangeFileEntry(root_only_file_entry.RootOnlyFileEntry):
Expand Down Expand Up @@ -36,21 +35,7 @@ def __init__(
is_virtual=is_virtual)
self.entry_type = definitions.FILE_ENTRY_TYPE_FILE

def _GetStat(self):
"""Retrieves a stat object.
Returns:
VFSStat: a stat object.
Raises:
BackEndError: when the encoded stream is missing.
"""
stat_object = vfs_stat.VFSStat()

# File data stat information.
stat_object.size = self.path_spec.range_size

# File entry type stat information.
stat_object.type = stat_object.TYPE_FILE

return stat_object
@property
def size(self):
"""int: size of the file entry in bytes or None if not available."""
return self.path_spec.range_size
19 changes: 4 additions & 15 deletions dfvfs/vfs/encoded_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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 EncodedStreamFileEntry(root_only_file_entry.RootOnlyFileEntry):
Expand Down Expand Up @@ -53,17 +52,7 @@ def __del__(self):

super(EncodedStreamFileEntry, self).__del__()

def _GetStat(self):
"""Retrieves information about the file entry.
Returns:
VFSStat: a stat object.
"""
stat_object = vfs_stat.VFSStat()

if self._encoded_stream:
stat_object.size = self._encoded_stream.get_size()

stat_object.type = self.entry_type

return stat_object
@property
def size(self):
"""int: size of the file entry in bytes or None if not available."""
return self._encoded_stream.get_size()
19 changes: 4 additions & 15 deletions dfvfs/vfs/encrypted_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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):
Expand Down Expand Up @@ -53,17 +52,7 @@ def __del__(self):

super(EncryptedStreamFileEntry, self).__del__()

def _GetStat(self):
"""Retrieves information about the file entry.
Returns:
VFSStat: a stat object.
"""
stat_object = vfs_stat.VFSStat()

if self._encrypted_stream:
stat_object.size = self._encrypted_stream.get_size()

stat_object.type = self.entry_type

return stat_object
@property
def size(self):
"""int: size of the file entry in bytes or None if not available."""
return self._encrypted_stream.get_size()
44 changes: 20 additions & 24 deletions dfvfs/vfs/fake_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,22 @@ def _GetDirectory(self):

return self._directory

def _GetStat(self):
"""Retrieves information about the file entry.
def _GetLink(self):
"""Retrieves the link.
Returns:
VFSStat: a stat object.
str: full path of the linked file entry.
"""
stat_object = super(FakeFileEntry, self)._GetStat()
if self._link is None:
self._link = ''

location = getattr(self.path_spec, 'location', None)
if location:
file_data = self._file_system.GetDataByPath(location)
location = getattr(self.path_spec, 'location', None)
if location is None:
return self._link

if file_data is not None:
stat_object.size = len(file_data)
self._link = self._file_system.GetDataByPath(location)

return stat_object
return self._link

def _GetSubFileEntries(self):
"""Retrieves sub file entries.
Expand Down Expand Up @@ -132,22 +132,18 @@ def name(self):
self._name = self._file_system.BasenamePath(location)
return self._name

def _GetLink(self):
"""Retrieves the link.
Returns:
str: full path of the linked file entry.
"""
if self._link is None:
self._link = ''

location = getattr(self.path_spec, 'location', None)
if location is None:
return self._link
@property
def size(self):
"""int: size of the file entry in bytes or None if not available."""
size = None

self._link = self._file_system.GetDataByPath(location)
location = getattr(self.path_spec, 'location', None)
if location:
file_data = self._file_system.GetDataByPath(location)
if file_data is not None:
size = len(file_data)

return self._link
return size

def GetFileObject(self, data_stream_name=''):
"""Retrieves the file-like object.
Expand Down
Loading

0 comments on commit 99aae01

Please sign in to comment.