Skip to content

Commit

Permalink
Removed GetStat file entry method #52 (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Jul 9, 2022
1 parent e312ea3 commit c034a7b
Show file tree
Hide file tree
Showing 39 changed files with 51 additions and 1,124 deletions.
19 changes: 0 additions & 19 deletions dfvfs/vfs/apfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,6 @@ def _GetLink(self):

return self._link

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

# 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

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

return stat_object

def _GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down
18 changes: 0 additions & 18 deletions dfvfs/vfs/cpio_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,6 @@ def _GetLink(self):

return self._link

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

# Ownership and permissions stat information.
mode = getattr(self._cpio_archive_file_entry, 'mode', 0)
stat_object.mode = stat.S_IMODE(mode)
stat_object.uid = getattr(
self._cpio_archive_file_entry, 'user_identifier', None)
stat_object.gid = getattr(
self._cpio_archive_file_entry, 'group_identifier', None)

return stat_object

def _GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down
27 changes: 0 additions & 27 deletions dfvfs/vfs/ext_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,6 @@ def _GetLink(self):

return self._link

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

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

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

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

# Other stat information.
stat_object.ino = self._fsext_file_entry.inode_number
stat_object.fs_type = 'EXT'

stat_object.is_allocated = True

return stat_object

def _GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down
73 changes: 0 additions & 73 deletions dfvfs/vfs/file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

import abc

from dfvfs.lib import decorators
from dfvfs.lib import definitions
from dfvfs.resolver import resolver
from dfvfs.vfs import data_stream
from dfvfs.vfs import vfs_stat


class FileEntry(object):
Expand Down Expand Up @@ -106,66 +104,6 @@ def _GetLink(self):

return self._link

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

# Date and time stat information.
access_time = self.access_time
if access_time:
stat_time, stat_time_nano = access_time.CopyToStatTimeTuple()
if stat_time is not None:
stat_object.atime = stat_time
if stat_time_nano is not None:
stat_object.atime_nano = stat_time_nano

change_time = self.change_time
if change_time:
stat_time, stat_time_nano = change_time.CopyToStatTimeTuple()
if stat_time is not None:
stat_object.ctime = stat_time
if stat_time_nano is not None:
stat_object.ctime_nano = stat_time_nano

creation_time = self.creation_time
if creation_time:
stat_time, stat_time_nano = creation_time.CopyToStatTimeTuple()
if stat_time is not None:
stat_object.crtime = stat_time
if stat_time_nano is not None:
stat_object.crtime_nano = stat_time_nano

modification_time = self.modification_time
if modification_time:
stat_time, stat_time_nano = modification_time.CopyToStatTimeTuple()
if stat_time is not None:
stat_object.mtime = stat_time
if stat_time_nano is not None:
stat_object.mtime_nano = stat_time_nano

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

# Ownership and permissions stat information.
# TODO: consider adding stat_object.mode
# TODO: consider adding stat_object.uid
# TODO: consider adding stat_object.gid

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

# Other stat information.
# TODO: consider adding stat_object.ino
# TODO: consider adding stat_object.fs_type

stat_object.is_allocated = self.IsAllocated()

return stat_object

def _GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down Expand Up @@ -379,17 +317,6 @@ def GetSubFileEntryByName(self, name, case_sensitive=True):

return matching_sub_file_entry

@decorators.deprecated
def GetStat(self):
"""Retrieves information about the file entry.
This method is deprecated use GetStatAttribute instead.
Returns:
VFSStat: a stat object or None if not available.
"""
return self._GetStat()

def GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down
27 changes: 0 additions & 27 deletions dfvfs/vfs/hfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,6 @@ def _GetLink(self):

return self._link

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

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

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

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

# Other stat information.
stat_object.ino = self._fshfs_file_entry.identifier
stat_object.fs_type = 'HFS'

stat_object.is_allocated = True

return stat_object

def _GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down
15 changes: 0 additions & 15 deletions dfvfs/vfs/ntfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,6 @@ def _GetLink(self):

return self._link

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

# Other stat information.
file_reference = self._fsntfs_file_entry.file_reference
stat_object.ino = file_reference & self._FILE_REFERENCE_MFT_ENTRY_BITMASK
stat_object.fs_type = 'NTFS'

return stat_object

def _GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down
19 changes: 0 additions & 19 deletions dfvfs/vfs/os_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,6 @@ def _GetLink(self):

return self._link

def _GetStat(self):
"""Retrieves information about the file entry.
Returns:
VFSStat: a stat object or None if not available.
"""
stat_object = super(OSFileEntry, self)._GetStat()

if not self._is_windows_device and self._stat_info:
# Ownership and permissions stat information.
stat_object.mode = stat.S_IMODE(self._stat_info.st_mode)
stat_object.uid = self._stat_info.st_uid
stat_object.gid = self._stat_info.st_gid

# Other stat information.
stat_object.ino = self._stat_info.st_ino

return stat_object

def _GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down
15 changes: 0 additions & 15 deletions dfvfs/vfs/tar_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,6 @@ def _GetLink(self):

return self._link

def _GetStat(self):
"""Retrieves the stat object.
Returns:
VFSStat: stat object.
"""
stat_object = super(TARFileEntry, self)._GetStat()

# Ownership and permissions stat information.
stat_object.mode = getattr(self._tar_info, 'mode', None)
stat_object.uid = getattr(self._tar_info, 'uid', None)
stat_object.gid = getattr(self._tar_info, 'gid', None)

return stat_object

def _GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down
84 changes: 0 additions & 84 deletions dfvfs/vfs/tsk_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,6 @@ def CopyToDateTimeString(self):
year, month, day_of_month, hours, minutes, seconds,
self.fraction_of_second)

def CopyToStatTimeTuple(self):
"""Copies the SleuthKit timestamp to a stat timestamp tuple.
Returns:
tuple[int, int]: a POSIX timestamp in seconds and the remainder in
100 nano seconds or (None, None) on error.
"""
if self.fraction_of_second is None:
return self._timestamp, None

return super(TSKTime, self).CopyToStatTimeTuple()

def GetDate(self):
"""Retrieves the date represented by the date and time values.
Expand Down Expand Up @@ -444,42 +432,6 @@ def _GetLink(self):

return self._link

def _GetStat(self):
"""Retrieves the stat object.
Returns:
VFSStat: stat object.
"""
stat_object = super(TSKFileEntry, self)._GetStat()

# Date and time stat information.
stat_time, stat_time_nano = self._TSKFileTimeCopyToStatTimeTuple(
self._tsk_file, 'bkup')
if stat_time is not None:
stat_object.bkup = stat_time
stat_object.bkup_nano = stat_time_nano

stat_time, stat_time_nano = self._TSKFileTimeCopyToStatTimeTuple(
self._tsk_file, 'dtime')
if stat_time is not None:
stat_object.dtime = stat_time
stat_object.dtime_nano = stat_time_nano

# Ownership and permissions stat information.
mode = getattr(self._tsk_file.info.meta, 'mode', None)
if mode is not None:
# We need to cast mode to an int since it is of type
# pytsk3.TSK_FS_META_MODE_ENUM.
stat_object.mode = int(mode)

stat_object.uid = getattr(self._tsk_file.info.meta, 'uid', None)
stat_object.gid = getattr(self._tsk_file.info.meta, 'gid', None)

# Other stat information.
stat_object.ino = getattr(self._tsk_file.info.meta, 'addr', None)

return stat_object

def _GetStatAttribute(self):
"""Retrieves a stat attribute.
Expand Down Expand Up @@ -575,42 +527,6 @@ def _GetTimeValue(self, name):
date_time.is_local_time = is_local_time
return date_time

def _TSKFileTimeCopyToStatTimeTuple(self, tsk_file, time_value):
"""Copies a SleuthKit file object time value to a stat timestamp tuple.
Args:
tsk_file (pytsk3.File): TSK file.
time_value (str): name of the time value.
Returns:
tuple[int, int]: number of seconds since 1970-01-01 00:00:00 and fraction
of second in 100 nano seconds intervals. The number of seconds is None
on error, or if the file system does not include the requested
timestamp. The fraction of second is None on error, or if the file
system does not support sub-second precision.
Raises:
BackEndError: if the TSK File .info, .info.meta or info.fs_info
attribute is missing.
"""
if (not tsk_file or not tsk_file.info or not tsk_file.info.meta or
not tsk_file.info.fs_info):
raise errors.BackEndError(
'Missing TSK File .info, .info.meta. or .info.fs_info')

stat_time = getattr(tsk_file.info.meta, time_value, None)
stat_time_nano = None
if self._file_system_type in self._TSK_HAS_NANO_FS_TYPES:
time_value_nano = '{0:s}_nano'.format(time_value)
stat_time_nano = getattr(tsk_file.info.meta, time_value_nano, None)

# Sleuthkit 4.2.0 switched from 100 nano seconds precision to
# 1 nano seconds precision.
if stat_time_nano is not None and pytsk3.TSK_VERSION_NUM >= 0x040200ff:
stat_time_nano /= 100

return stat_time, stat_time_nano

@property
def access_time(self):
"""dfdatetime.DateTimeValues: access time or None if not available."""
Expand Down
Loading

0 comments on commit c034a7b

Please sign in to comment.