def testComparable(self):
        """Tests the path specification comparable property."""
        path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name='test_table',
            column_name='test_column',
            row_condition=('identifier', '==', 0),
            parent=self._path_spec)

        self.assertIsNotNone(path_spec)

        expected_comparable = '\n'.join([
            'type: TEST',
            ('type: SQLITE_BLOB, table name: test_table, '
             'column name: test_column, row condition: "identifier == 0"'), ''
        ])

        self.assertEqual(path_spec.comparable, expected_comparable)

        path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name='test_table',
            column_name='test_column',
            row_index=0,
            parent=self._path_spec)

        self.assertIsNotNone(path_spec)

        expected_comparable = '\n'.join([
            'type: TEST',
            ('type: SQLITE_BLOB, table name: test_table, '
             'column name: test_column, row index: 0'), ''
        ])

        self.assertEqual(path_spec.comparable, expected_comparable)
  def _EntriesGenerator(self):
    """Retrieves directory entries.

    Since a directory can contain a vast number of entries using
    a generator is more memory efficient.

    Yields:
      SQLiteBlobPathSpec: a path specification.

    Raises:
      AccessError: if the access to list the directory was denied.
      BackEndError: if the directory could not be listed.
    """
    table_name = getattr(self.path_spec, 'table_name', None)
    column_name = getattr(self.path_spec, 'column_name', None)

    if table_name and column_name:
      if self._number_of_entries is None:
        # Open the first entry to determine how many entries we have.
        # TODO: change this when there is a move this to a central temp file
        # manager. https://github.com/log2timeline/dfvfs/issues/92
        path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name=table_name, column_name=column_name, row_index=0,
            parent=self.path_spec.parent)

        sub_file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
        if not file_entry:
          self._number_of_entries = 0
        else:
          self._number_of_entries = sub_file_entry.GetNumberOfRows()

      for row_index in range(0, self._number_of_entries):
        yield sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name=table_name, column_name=column_name, row_index=row_index,
            parent=self.path_spec.parent)
Exemple #3
0
    def setUp(self):
        """Sets up the needed objects used throughout the test."""
        self._resolver_context = context.Context()
        test_file = self._GetTestFilePath(['blob.db'])
        path_spec = os_path_spec.OSPathSpec(location=test_file)
        self._sqlite_blob_path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name='myblobs',
            column_name='blobs',
            row_condition=('name', '==', 'mmssms.db'),
            parent=path_spec)
        self._sqlite_blob_path_spec_2 = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name='myblobs',
            column_name='blobs',
            row_index=2,
            parent=path_spec)
        self._sqlite_blob_path_spec_3 = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name='myblobs',
            column_name='blobs',
            row_condition=('name', '==', 4),
            parent=path_spec)
        self._sqlite_blob_path_spec_directory = (
            sqlite_blob_path_spec.SQLiteBlobPathSpec(table_name='myblobs',
                                                     column_name='blobs',
                                                     parent=path_spec))

        self._file_system = sqlite_blob_file_system.SQLiteBlobFileSystem(
            self._resolver_context)
        self._file_system.Open(self._sqlite_blob_path_spec)
Exemple #4
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._resolver_context = context.Context()
     test_file = self._GetTestFilePath([u'blob.db'])
     path_spec = os_path_spec.OSPathSpec(location=test_file)
     self._sqlite_blob_path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
         table_name=u'myblobs',
         column_name=u'blobs',
         row_condition=(u'name', u'==', u'mmssms.db'),
         parent=path_spec)
     self._sqlite_blob_path_spec_2 = sqlite_blob_path_spec.SQLiteBlobPathSpec(
         table_name=u'myblobs',
         column_name=u'blobs',
         row_index=2,
         parent=path_spec)
    def _EntriesGenerator(self):
        """Retrieves directory entries.

       Since a directory can contain a vast number of entries using
       a generator is more memory efficient.

    Yields:
      A path specification (instance of path.SQLiteBlobPathSpec).

    Raises:
      AccessError: if the access to list the directory was denied.
      BackEndError: if the directory could not be listed.
    """
        table_name = getattr(self.path_spec, u'table_name', None)
        if table_name is None:
            return

        column_name = getattr(self.path_spec, u'column_name', None)
        if column_name is None:
            return

        number_of_rows = self._file_system.GetNumberOfRows(self.path_spec)
        for row_index in range(0, number_of_rows):
            yield sqlite_blob_path_spec.SQLiteBlobPathSpec(
                table_name=table_name,
                column_name=column_name,
                row_index=row_index,
                parent=self.path_spec.parent)
Exemple #6
0
 def setUp(self):
   """Sets up the needed objects used throughout the test."""
   self._resolver_context = context.Context()
   test_file = self._GetTestFilePath(['syslog.db'])
   path_spec = os_path_spec.OSPathSpec(location=test_file)
   self._sqlite_blob_path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
       table_name='blobs', column_name='blob', row_index=0, parent=path_spec)
Exemple #7
0
  def setUp(self):
    """Sets up the needed objects used throughout the test."""
    self._resolver_context = context.Context()
    test_file = self._GetTestFilePath(['syslog.db'])
    self._SkipIfPathNotExists(test_file)

    path_spec = os_path_spec.OSPathSpec(location=test_file)
    self._sqlite_blob_path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
        table_name='blobs', column_name='blob',
        row_condition=('identifier', '==', 'myblob'), parent=path_spec)
Exemple #8
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._resolver_context = context.Context()
     test_file = os.path.join(u'test_data', u'syslog.db')
     path_spec = os_path_spec.OSPathSpec(location=test_file)
     self._sqlite_blob_path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
         table_name=u'blobs',
         column_name=u'blob',
         row_condition=(u'identifier', u'==', u'myblob'),
         parent=path_spec)
    def setUp(self):
        """Sets up the needed objects used throughout the test."""
        self._resolver_context = context.Context()
        test_file = os.path.join(u'test_data', u'blob.db')
        path_spec = os_path_spec.OSPathSpec(location=test_file)
        self._sqlite_blob_path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name=u'myblobs',
            column_name=u'blobs',
            row_condition=(u'name', u'==', u'mmssms.db'),
            parent=path_spec)
        self._sqlite_blob_path_spec_2 = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name=u'myblobs',
            column_name=u'blobs',
            row_index=2,
            parent=path_spec)

        self._file_system = sqlite_blob_file_system.SQLiteBlobFileSystem(
            self._resolver_context)
        self._file_system.Open(path_spec=self._sqlite_blob_path_spec)
Exemple #10
0
    def GetRootFileEntry(self):
        """Retrieves the root file entry.

    Returns:
      FileEntry: a file entry or None.
    """
        path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name=self._path_spec.table_name,
            column_name=self._path_spec.column_name,
            parent=self._path_spec.parent)
        return self.GetFileEntryByPathSpec(path_spec)
 def GetParentFileEntry(self):
     """Retrieves the parent file entry."""
     # If the file entry is a sub entry, return the SQLite blob directory.
     if not self._is_virtual:
         path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
             table_name=self.path_spec.table_name,
             column_name=self.path_spec.column_name,
             parent=self.path_spec.parent)
         return SQLiteBlobFileEntry(self._resolver_context,
                                    self._file_system,
                                    path_spec,
                                    is_root=True,
                                    is_virtual=True)
    def testInitialize(self):
        """Tests the path specification initialization."""
        path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name='test_table',
            column_name='test_column',
            row_condition=('identifier', '==', 0),
            parent=self._path_spec)

        self.assertIsNotNone(path_spec)

        path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
            table_name='test_table',
            column_name='test_column',
            row_index=0,
            parent=self._path_spec)

        self.assertIsNotNone(path_spec)

        with self.assertRaises(ValueError):
            sqlite_blob_path_spec.SQLiteBlobPathSpec(table_name='test_table',
                                                     column_name='test_column',
                                                     row_index=0,
                                                     parent=None)

        with self.assertRaises(ValueError):
            sqlite_blob_path_spec.SQLiteBlobPathSpec(table_name=None,
                                                     column_name='test_column',
                                                     row_index=0,
                                                     parent=self._path_spec)

        with self.assertRaises(ValueError):
            sqlite_blob_path_spec.SQLiteBlobPathSpec(table_name='test_table',
                                                     column_name=None,
                                                     row_index=0,
                                                     parent=self._path_spec)

        with self.assertRaises(ValueError):
            sqlite_blob_path_spec.SQLiteBlobPathSpec(
                table_name='test_table',
                column_name='test_column',
                row_condition='identifier == 0',
                parent=self._path_spec)

        with self.assertRaises(ValueError):
            sqlite_blob_path_spec.SQLiteBlobPathSpec(table_name='test_table',
                                                     column_name='test_column',
                                                     row_index=0,
                                                     parent=self._path_spec,
                                                     bogus='BOGUS')