Exemplo n.º 1
0
    def GetFileEntryByPathSpec(self, path_spec):
        """Retrieves a file entry for a path specification.

    Args:
      path_spec (PathSpec): path specification.

    Returns:
      TARFileEntry: file entry or None.
    """
        if not self.FileEntryExistsByPathSpec(path_spec):
            return None

        location = getattr(path_spec, 'location', None)

        if len(location) == 1:
            return tar_file_entry.TARFileEntry(self._resolver_context,
                                               self,
                                               path_spec,
                                               is_root=True,
                                               is_virtual=True)

        kwargs = {}
        try:
            kwargs['tar_info'] = self._tar_file.getmember(location[1:])
        except KeyError:
            kwargs['is_virtual'] = True

        return tar_file_entry.TARFileEntry(self._resolver_context, self,
                                           path_spec, **kwargs)
Exemplo n.º 2
0
    def testIntialize(self):
        """Test the initialize functionality."""
        file_entry = tar_file_entry.TARFileEntry(self._resolver_context,
                                                 self._file_system,
                                                 self._tar_path_spec)

        self.assertIsNotNone(file_entry)
Exemplo n.º 3
0
    def testSize(self):
        """Test the size property."""
        file_entry = tar_file_entry.TARFileEntry(self._resolver_context,
                                                 self._file_system,
                                                 self._tar_path_spec)

        self.assertIsNotNone(file_entry)
        self.assertEqual(file_entry.size, 1247)
Exemplo n.º 4
0
    def testModificationTime(self):
        """Test the modification_time property."""
        file_entry = tar_file_entry.TARFileEntry(self._resolver_context,
                                                 self._file_system,
                                                 self._tar_path_spec)

        self.assertIsNotNone(file_entry)
        self.assertIsNotNone(file_entry.modification_time)
Exemplo n.º 5
0
    def testName(self):
        """Test the name property."""
        file_entry = tar_file_entry.TARFileEntry(self._resolver_context,
                                                 self._file_system,
                                                 self._tar_path_spec)

        self.assertIsNotNone(file_entry)
        self.assertEqual(file_entry.name, 'syslog')