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.
Added attributes support for fshfs back-end log2timeline#504 (log2tim…
- Loading branch information
1 parent
10f8979
commit 5dc1686
Showing
18 changed files
with
344 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# -*- coding: utf-8 -*- | ||
"""The HFS attribute implementation.""" | ||
|
||
import os | ||
|
||
from dfvfs.lib import errors | ||
from dfvfs.vfs import attribute | ||
|
||
|
||
class HFSExtendedAttribute(attribute.Attribute): | ||
"""HFS extended attribute that uses pyfshfs.""" | ||
|
||
def __init__(self, fshfs_extended_attribute): | ||
"""Initializes an attribute. | ||
Args: | ||
fshfs_extended_attribute (pyfshfs.extended_attribute): HFS extended | ||
attribute. | ||
Raises: | ||
BackEndError: if the pyfshfs extended attribute is missing. | ||
""" | ||
if not fshfs_extended_attribute: | ||
raise errors.BackEndError('Missing pyfshfs extended attribute.') | ||
|
||
super(HFSExtendedAttribute, self).__init__() | ||
self._fshfs_extended_attribute = fshfs_extended_attribute | ||
|
||
@property | ||
def name(self): | ||
"""str: name.""" | ||
return self._fshfs_extended_attribute.name | ||
|
||
# Note: that the following functions do not follow the style guide | ||
# because they are part of the file-like object interface. | ||
# pylint: disable=invalid-name | ||
|
||
def read(self, size=None): | ||
"""Reads a byte string from the file input/output (IO) object. | ||
The function will read a byte string of the specified size or | ||
all of the remaining data if no size was specified. | ||
Args: | ||
size (Optional[int]): number of bytes to read, where None is all | ||
remaining data. | ||
Returns: | ||
bytes: data read. | ||
Raises: | ||
IOError: if the read failed. | ||
OSError: if the read failed. | ||
""" | ||
return self._fshfs_extended_attribute.read_buffer(size) | ||
|
||
def seek(self, offset, whence=os.SEEK_SET): | ||
"""Seeks to an offset within the file input/output (IO) object. | ||
Args: | ||
offset (int): offset to seek. | ||
whence (Optional[int]): value that indicates whether offset is an | ||
absolute or relative position within the file. | ||
Raises: | ||
IOError: if the seek failed. | ||
OSError: if the seek failed. | ||
""" | ||
self._fshfs_extended_attribute.seek_offset(offset, whence) | ||
|
||
# get_offset() is preferred above tell() by the libbfio layer used in libyal. | ||
def get_offset(self): | ||
"""Retrieves the current offset into the file input/output (IO) object. | ||
Returns: | ||
int: current offset into the file input/output (IO) object. | ||
Raises: | ||
IOError: if the file input/output (IO)-like object has not been opened. | ||
OSError: if the file input/output (IO)-like object has not been opened. | ||
""" | ||
return self._fshfs_extended_attribute.get_offset() | ||
|
||
# Pythonesque alias for get_offset(). | ||
def tell(self): | ||
"""Retrieves the current offset into the file input/output (IO) object.""" | ||
return self.get_offset() | ||
|
||
def get_size(self): | ||
"""Retrieves the size of the file input/output (IO) object. | ||
Returns: | ||
int: size of the file input/output (IO) object. | ||
Raises: | ||
IOError: if the file input/output (IO) object has not been opened. | ||
OSError: if the file input/output (IO) object has not been opened. | ||
""" | ||
return self._fshfs_extended_attribute.get_size() | ||
|
||
def seekable(self): | ||
"""Determines if a file input/output (IO) object is seekable. | ||
Returns: | ||
bool: True since a file IO object provides a seek method. | ||
""" | ||
return True |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
"""Tests for the HFS attribute.""" | ||
|
||
import unittest | ||
|
||
from dfvfs.lib import definitions | ||
from dfvfs.lib import errors | ||
from dfvfs.path import factory as path_spec_factory | ||
from dfvfs.resolver import context | ||
from dfvfs.vfs import hfs_attribute | ||
from dfvfs.vfs import hfs_file_system | ||
|
||
from tests import test_lib as shared_test_lib | ||
|
||
|
||
class HFSAttributeTest(shared_test_lib.BaseTestCase): | ||
"""Tests the HFS attribute.""" | ||
|
||
# pylint: disable=protected-access | ||
|
||
_IDENTIFIER_A_FILE = 19 | ||
|
||
def setUp(self): | ||
"""Sets up the needed objects used throughout the test.""" | ||
self._resolver_context = context.Context() | ||
test_path = self._GetTestFilePath(['hfsplus.raw']) | ||
self._SkipIfPathNotExists(test_path) | ||
|
||
test_os_path_spec = path_spec_factory.Factory.NewPathSpec( | ||
definitions.TYPE_INDICATOR_OS, location=test_path) | ||
self._raw_path_spec = path_spec_factory.Factory.NewPathSpec( | ||
definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec) | ||
self._hfs_path_spec = path_spec_factory.Factory.NewPathSpec( | ||
definitions.TYPE_INDICATOR_HFS, location='/', | ||
parent=self._raw_path_spec) | ||
|
||
self._file_system = hfs_file_system.HFSFileSystem( | ||
self._resolver_context, self._hfs_path_spec) | ||
self._file_system.Open() | ||
|
||
def tearDown(self): | ||
"""Cleans up the needed objects used throughout the test.""" | ||
self._resolver_context.Empty() | ||
|
||
def testIntialize(self): | ||
"""Tests the __init__ function.""" | ||
test_location = '/a_directory/a_file' | ||
path_spec = path_spec_factory.Factory.NewPathSpec( | ||
definitions.TYPE_INDICATOR_HFS, identifier=self._IDENTIFIER_A_FILE, | ||
location=test_location, parent=self._raw_path_spec) | ||
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) | ||
|
||
fshfs_attribute = file_entry._fshfs_file_entry.get_extended_attribute(0) | ||
self.assertIsNotNone(fshfs_attribute) | ||
self.assertEqual(fshfs_attribute.name, 'myxattr') | ||
|
||
test_attribute = hfs_attribute.HFSExtendedAttribute(fshfs_attribute) | ||
self.assertIsNotNone(test_attribute) | ||
|
||
with self.assertRaises(errors.BackEndError): | ||
hfs_attribute.HFSExtendedAttribute(None) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.