def testComparable(self): """Tests the path specification comparable property.""" path_spec = tar_path_spec.TARPathSpec(location='/test', parent=self._path_spec) self.assertIsNotNone(path_spec) expected_comparable = '\n'.join( ['type: TEST', 'type: TAR, location: /test', '']) self.assertEqual(path_spec.comparable, expected_comparable)
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = self._GetTestFilePath(['syslog.tar']) self._os_path_spec = os_path_spec.OSPathSpec(location=test_file) self._tar_path_spec = tar_path_spec.TARPathSpec( location='/syslog', parent=self._os_path_spec) self._file_system = tar_file_system.TARFileSystem( self._resolver_context) self._file_system.Open(self._tar_path_spec)
def testGetParentFileEntry(self): """Tests the GetParentFileEntry function.""" path_spec = tar_path_spec.TARPathSpec( location='/syslog', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) parent_file_entry = file_entry.GetParentFileEntry() self.assertIsNotNone(parent_file_entry) self.assertEqual(parent_file_entry.name, '')
def testFileEntryExistsByPathSpec(self): """Test the file entry exists by path specification functionality.""" file_system = tar_file_system.TARFileSystem(self._resolver_context) self.assertIsNotNone(file_system) file_system.Open(self._tar_path_spec) path_spec = tar_path_spec.TARPathSpec(location='/syslog', parent=self._os_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = tar_path_spec.TARPathSpec(location='/bogus', parent=self._os_path_spec) self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec)) file_system.Close() # Test on a tar file that has missing directory entries. test_file = self._GetTestFilePath(['missing_directory_entries.tar']) self._SkipIfPathNotExists(test_file) test_file_path_spec = os_path_spec.OSPathSpec(location=test_file) path_spec = tar_path_spec.TARPathSpec(location='/', parent=test_file_path_spec) file_system = tar_file_system.TARFileSystem(self._resolver_context) self.assertIsNotNone(file_system) file_system.Open(path_spec) path_spec = tar_path_spec.TARPathSpec(location='/File System', parent=test_file_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = tar_path_spec.TARPathSpec( location='/File System/Recordings', parent=test_file_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) file_system.Close()
def testGetDataStream(self): """Tests the GetDataStream function.""" path_spec = tar_path_spec.TARPathSpec( location='/syslog', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) data_stream_name = '' data_stream = file_entry.GetDataStream(data_stream_name) self.assertIsNotNone(data_stream) self.assertEqual(data_stream.name, data_stream_name) data_stream = file_entry.GetDataStream('bogus') self.assertIsNone(data_stream)
def testGetStat(self): """Tests the GetStat function.""" path_spec = tar_path_spec.TARPathSpec( location='/syslog', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) stat_object = file_entry.GetStat() self.assertIsNotNone(stat_object) self.assertEqual(stat_object.type, stat_object.TYPE_FILE) self.assertEqual(stat_object.size, 1247) self.assertEqual(stat_object.mode, 256) self.assertEqual(stat_object.uid, 151107) self.assertEqual(stat_object.gid, 5000) self.assertEqual(stat_object.mtime, 1343166324) self.assertFalse(hasattr(stat_object, 'mtime_nano'))
def GetParentFileEntry(self): """Retrieves the parent file entry. Returns: TARFileEntry: parent file entry or None. """ location = getattr(self.path_spec, u'location', None) if location is None: return parent_location = self._file_system.DirnamePath(location) if parent_location is None: return if parent_location == u'': parent_location = self._file_system.PATH_SEPARATOR parent_path_spec = getattr(self.path_spec, u'parent', None) path_spec = tar_path_spec.TARPathSpec(location=parent_location, parent=parent_path_spec) return TARFileEntry(self._resolver_context, self._file_system, path_spec)