Skip to content

Commit

Permalink
Changed file entry type to public attribute log2timeline#52
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Feb 22, 2018
1 parent d1cdb0e commit 3527ed2
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 75 deletions.
2 changes: 1 addition & 1 deletion dfvfs/vfs/bde_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(
resolver_context, file_system, path_spec, is_root=is_root,
is_virtual=is_virtual)
self._bde_volume = bde_volume
self._type = definitions.FILE_ENTRY_TYPE_FILE
self.type = definitions.FILE_ENTRY_TYPE_FILE

def _GetStat(self):
"""Retrieves information about the file entry.
Expand Down
4 changes: 2 additions & 2 deletions dfvfs/vfs/compressed_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __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
self.type = definitions.FILE_ENTRY_TYPE_FILE

def __del__(self):
"""Cleans up the file entry."""
Expand All @@ -64,6 +64,6 @@ def _GetStat(self):
if self._compressed_stream:
stat_object.size = self._compressed_stream.get_size()

stat_object.type = self._type
stat_object.type = self.type

return stat_object
16 changes: 8 additions & 8 deletions dfvfs/vfs/cpio_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,26 @@ def __init__(
# for LINK first.
mode = getattr(cpio_archive_file_entry, 'mode', 0)
if stat.S_ISLNK(mode):
self._type = definitions.FILE_ENTRY_TYPE_LINK
self.type = definitions.FILE_ENTRY_TYPE_LINK
# The root file entry is virtual and should have type directory.
elif is_virtual or stat.S_ISDIR(mode):
self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY
self.type = definitions.FILE_ENTRY_TYPE_DIRECTORY
elif stat.S_ISREG(mode):
self._type = definitions.FILE_ENTRY_TYPE_FILE
self.type = definitions.FILE_ENTRY_TYPE_FILE
elif stat.S_ISCHR(mode) or stat.S_ISBLK(mode):
self._type = definitions.FILE_ENTRY_TYPE_DEVICE
self.type = definitions.FILE_ENTRY_TYPE_DEVICE
elif stat.S_ISFIFO(mode):
self._type = definitions.FILE_ENTRY_TYPE_PIPE
self.type = definitions.FILE_ENTRY_TYPE_PIPE
elif stat.S_ISSOCK(mode):
self._type = definitions.FILE_ENTRY_TYPE_SOCKET
self.type = definitions.FILE_ENTRY_TYPE_SOCKET

def _GetDirectory(self):
"""Retrieves a directory.
Returns:
CPIODirectory: a directory or None if not available.
"""
if self._type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
if self.type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
return CPIODirectory(self._file_system, self.path_spec)

def _GetLink(self):
Expand All @@ -124,7 +124,7 @@ def _GetLink(self):
if self._link is None:
self._link = ''

if self._type != definitions.FILE_ENTRY_TYPE_LINK:
if self.type != definitions.FILE_ENTRY_TYPE_LINK:
return self._link

cpio_archive_file = self._file_system.GetCPIOArchiveFile()
Expand Down
4 changes: 2 additions & 2 deletions dfvfs/vfs/encoded_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __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
self.type = definitions.FILE_ENTRY_TYPE_FILE

def __del__(self):
"""Cleans up the file entry."""
Expand All @@ -64,6 +64,6 @@ def _GetStat(self):
if self._encoded_stream:
stat_object.size = self._encoded_stream.get_size()

stat_object.type = self._type
stat_object.type = self.type

return stat_object
4 changes: 2 additions & 2 deletions dfvfs/vfs/encrypted_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __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
self.type = definitions.FILE_ENTRY_TYPE_FILE

def __del__(self):
"""Cleans up the file entry."""
Expand All @@ -64,6 +64,6 @@ def _GetStat(self):
if self._encrypted_stream:
stat_object.size = self._encrypted_stream.get_size()

stat_object.type = self._type
stat_object.type = self.type

return stat_object
4 changes: 2 additions & 2 deletions dfvfs/vfs/fake_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ def __init__(
is_virtual=True)
self._date_time = dfdatetime_fake_time.FakeTime()
self._name = None
self._type = file_entry_type
self.type = file_entry_type

def _GetDirectory(self):
"""Retrieves a directory.
Returns:
FakeDirectory: a directory or None if not available.
"""
if self._type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
if self.type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
return FakeDirectory(self._file_system, self.path_spec)

def _GetStat(self):
Expand Down
37 changes: 21 additions & 16 deletions dfvfs/vfs/file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ def entries(self):


class FileEntry(object):
"""VFS file entry interface."""
"""VFS file entry interface.
Attributes:
path_spec (PathSpec): path specification.
type (int): file entry type or None if not available.
"""

def __init__(
self, resolver_context, file_system, path_spec, is_root=False,
Expand All @@ -111,8 +116,8 @@ def __init__(
self._link = None
self._resolver_context = resolver_context
self._stat_object = None
self._type = None
self.path_spec = path_spec
self.type = None

self._file_system.Open(path_spec)

Expand Down Expand Up @@ -214,8 +219,8 @@ def _GetStat(self):
stat_object.mtime_nano = stat_time_nano

# File entry type stat information.
if self._type:
stat_object.type = self._type
if self.type:
stat_object.type = self.type

return stat_object

Expand Down Expand Up @@ -449,8 +454,8 @@ def IsDevice(self):
if self._stat_object is None:
self._stat_object = self._GetStat()
if self._stat_object is not None:
self._type = self._stat_object.type
return self._type == definitions.FILE_ENTRY_TYPE_DEVICE
self.type = self._stat_object.type
return self.type == definitions.FILE_ENTRY_TYPE_DEVICE

def IsDirectory(self):
"""Determines if the file entry is a directory.
Expand All @@ -461,8 +466,8 @@ def IsDirectory(self):
if self._stat_object is None:
self._stat_object = self._GetStat()
if self._stat_object is not None:
self._type = self._stat_object.type
return self._type == definitions.FILE_ENTRY_TYPE_DIRECTORY
self.type = self._stat_object.type
return self.type == definitions.FILE_ENTRY_TYPE_DIRECTORY

def IsFile(self):
"""Determines if the file entry is a file.
Expand All @@ -473,8 +478,8 @@ def IsFile(self):
if self._stat_object is None:
self._stat_object = self._GetStat()
if self._stat_object is not None:
self._type = self._stat_object.type
return self._type == definitions.FILE_ENTRY_TYPE_FILE
self.type = self._stat_object.type
return self.type == definitions.FILE_ENTRY_TYPE_FILE

def IsLink(self):
"""Determines if the file entry is a link.
Expand All @@ -485,8 +490,8 @@ def IsLink(self):
if self._stat_object is None:
self._stat_object = self._GetStat()
if self._stat_object is not None:
self._type = self._stat_object.type
return self._type == definitions.FILE_ENTRY_TYPE_LINK
self.type = self._stat_object.type
return self.type == definitions.FILE_ENTRY_TYPE_LINK

def IsPipe(self):
"""Determines if the file entry is a pipe.
Expand All @@ -497,8 +502,8 @@ def IsPipe(self):
if self._stat_object is None:
self._stat_object = self._GetStat()
if self._stat_object is not None:
self._type = self._stat_object.type
return self._type == definitions.FILE_ENTRY_TYPE_PIPE
self.type = self._stat_object.type
return self.type == definitions.FILE_ENTRY_TYPE_PIPE

def IsRoot(self):
"""Determines if the file entry is the root file entry.
Expand All @@ -517,8 +522,8 @@ def IsSocket(self):
if self._stat_object is None:
self._stat_object = self._GetStat()
if self._stat_object is not None:
self._type = self._stat_object.type
return self._type == definitions.FILE_ENTRY_TYPE_SOCKET
self.type = self._stat_object.type
return self.type == definitions.FILE_ENTRY_TYPE_SOCKET

def IsVirtual(self):
"""Determines if the file entry is virtual (emulated by dfVFS).
Expand Down
2 changes: 1 addition & 1 deletion dfvfs/vfs/fvde_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __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
self.type = definitions.FILE_ENTRY_TYPE_FILE

def _GetStat(self):
"""Retrieves information about the file entry.
Expand Down
2 changes: 1 addition & 1 deletion dfvfs/vfs/gzip_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __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
self.type = definitions.FILE_ENTRY_TYPE_FILE

def __del__(self):
"""Cleans up the file entry."""
Expand Down
6 changes: 3 additions & 3 deletions dfvfs/vfs/lvm_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ def __init__(
self._vslvm_logical_volume = vslvm_logical_volume

if self._is_virtual:
self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY
self.type = definitions.FILE_ENTRY_TYPE_DIRECTORY
else:
self._type = definitions.FILE_ENTRY_TYPE_FILE
self.type = definitions.FILE_ENTRY_TYPE_FILE

def _GetDirectory(self):
"""Retrieves the directory.
Returns:
LVMDirectory: a directory or None if not available.
"""
if self._type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
if self.type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
return LVMDirectory(self._file_system, self.path_spec)

def _GetStat(self):
Expand Down
6 changes: 3 additions & 3 deletions dfvfs/vfs/ntfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ def __init__(
self._fsntfs_file_entry = fsntfs_file_entry

if self._IsLink(fsntfs_file_entry.file_attribute_flags):
self._type = definitions.FILE_ENTRY_TYPE_LINK
self.type = definitions.FILE_ENTRY_TYPE_LINK
elif fsntfs_file_entry.has_directory_entries_index():
self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY
self.type = definitions.FILE_ENTRY_TYPE_DIRECTORY
else:
self._type = definitions.FILE_ENTRY_TYPE_FILE
self.type = definitions.FILE_ENTRY_TYPE_FILE

def _GetAttributes(self):
"""Retrieves the attributes.
Expand Down
16 changes: 8 additions & 8 deletions dfvfs/vfs/os_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(self, resolver_context, file_system, path_spec, is_root=False):
self._stat_info = stat_info

if is_windows_device:
self._type = definitions.FILE_ENTRY_TYPE_DEVICE
self.type = definitions.FILE_ENTRY_TYPE_DEVICE

elif stat_info:
# If location contains a trailing segment separator and points to
Expand All @@ -130,26 +130,26 @@ def __init__(self, resolver_context, file_system, path_spec, is_root=False):
# dfVFS currently only supports one type so we need to check
# for LINK first.
if stat.S_ISLNK(stat_info.st_mode) or is_link:
self._type = definitions.FILE_ENTRY_TYPE_LINK
self.type = definitions.FILE_ENTRY_TYPE_LINK
elif stat.S_ISREG(stat_info.st_mode):
self._type = definitions.FILE_ENTRY_TYPE_FILE
self.type = definitions.FILE_ENTRY_TYPE_FILE
elif stat.S_ISDIR(stat_info.st_mode):
self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY
self.type = definitions.FILE_ENTRY_TYPE_DIRECTORY
elif (stat.S_ISCHR(stat_info.st_mode) or
stat.S_ISBLK(stat_info.st_mode)):
self._type = definitions.FILE_ENTRY_TYPE_DEVICE
self.type = definitions.FILE_ENTRY_TYPE_DEVICE
elif stat.S_ISFIFO(stat_info.st_mode):
self._type = definitions.FILE_ENTRY_TYPE_PIPE
self.type = definitions.FILE_ENTRY_TYPE_PIPE
elif stat.S_ISSOCK(stat_info.st_mode):
self._type = definitions.FILE_ENTRY_TYPE_SOCKET
self.type = definitions.FILE_ENTRY_TYPE_SOCKET

def _GetDirectory(self):
"""Retrieves a directory.
Returns:
OSDirectory: a directory object or None if not available.
"""
if self._type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
if self.type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
return OSDirectory(self._file_system, self.path_spec)

def _GetLink(self):
Expand Down
6 changes: 3 additions & 3 deletions dfvfs/vfs/sqlite_blob_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ def __init__(
self._number_of_entries = None

if is_virtual:
self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY
self.type = definitions.FILE_ENTRY_TYPE_DIRECTORY
else:
self._type = definitions.FILE_ENTRY_TYPE_FILE
self.type = definitions.FILE_ENTRY_TYPE_FILE

def _GetDirectory(self):
"""Retrieves a directory.
Returns:
SQLiteBlobDirectory: a directory or None if not available.
"""
if self._type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
if self.type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
return SQLiteBlobDirectory(self._file_system, self.path_spec)

def _GetStat(self):
Expand Down
12 changes: 6 additions & 6 deletions dfvfs/vfs/tar_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,23 @@ def __init__(
self._tar_info = tar_info

if self._is_virtual or self._tar_info.isdir():
self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY
self.type = definitions.FILE_ENTRY_TYPE_DIRECTORY
elif self._tar_info.isfile():
self._type = definitions.FILE_ENTRY_TYPE_FILE
self.type = definitions.FILE_ENTRY_TYPE_FILE
elif self._tar_info.issym() or self._tar_info.islnk():
self._type = definitions.FILE_ENTRY_TYPE_LINK
self.type = definitions.FILE_ENTRY_TYPE_LINK
elif self._tar_info.ischr() or self._tar_info.isblk():
self._type = definitions.FILE_ENTRY_TYPE_DEVICE
self.type = definitions.FILE_ENTRY_TYPE_DEVICE
elif self._tar_info.isfifo():
self._type = definitions.FILE_ENTRY_TYPE_PIPE
self.type = definitions.FILE_ENTRY_TYPE_PIPE

def _GetDirectory(self):
"""Retrieves a directory.
Returns:
TARDirectory: a directory or None if not available.
"""
if self._type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
if self.type == definitions.FILE_ENTRY_TYPE_DIRECTORY:
return TARDirectory(self._file_system, self.path_spec)

def _GetLink(self):
Expand Down
Loading

0 comments on commit 3527ed2

Please sign in to comment.