static void test_all(TestData *testdata, G_GNUC_UNUSED gconstpointer test_data) { GError *err = NULL; gchar *path; cr_SqliteDb *db = NULL; cr_Package *pkg, *pkg2 = NULL; // Create new db path = g_strconcat(testdata->tmp_dir, "/", TMP_PRIMARY_NAME, NULL); db = cr_db_open_primary(path, &err); g_assert(db); g_assert(!err); g_assert(g_file_test(path, G_FILE_TEST_EXISTS)); // Try cr_db_dbinfo_update cr_db_dbinfo_update(db, "foochecksum", &err); g_assert(!err); // Load package cr_package_parser_init(); pkg = cr_package_from_rpm(EMPTY_PKG, CR_CHECKSUM_SHA256, EMPTY_PKG, NULL, 5, NULL, CR_HDRR_NONE, NULL); g_assert(pkg); cr_package_parser_cleanup(); pkg2 = get_empty_package(); // Add package cr_db_add_pkg(db, pkg, &err); g_assert(!err); cr_db_add_pkg(db, pkg2, &err); g_assert(!err); // Try cr_db_dbinfo_update again cr_db_dbinfo_update(db, "foochecksum", &err); g_assert(!err); // Cleanup cr_package_free(pkg); cr_package_free(pkg2); cr_db_close(db, &err); g_assert(!err); g_free(path); }
static int pkgcb_interrupt(cr_Package *pkg, void *cbdata, GError **err) { g_assert(pkg); g_assert(!err || *err == NULL); if (cbdata) *((int *)cbdata) += 1; cr_package_free(pkg); return CR_CB_RET_ERR; }
static void package_dealloc(_PackageObject *self) { if (self->package && self->free_on_destroy) cr_package_free(self->package); if (self->parent) { Py_DECREF(self->parent); self->parent = NULL; } Py_TYPE(self)->tp_free(self); }
static int pkgcb(cr_Package *pkg, void *cbdata, GError **err) { int rc; rc = cr_db_add_pkg((cr_SqliteDb *) cbdata, pkg, err); cr_package_free(pkg); if (rc != CRE_OK) return CR_CB_RET_ERR; return CR_CB_RET_OK; }
PyObject * Object_FromPackage(cr_Package *pkg, int free_on_destroy) { PyObject *pypkg; if (!pkg) { PyErr_SetString(PyExc_ValueError, "Expected a cr_Package pointer not NULL."); return NULL; } pypkg = PyObject_CallObject((PyObject*)&Package_Type, NULL); // XXX: Remove empty package in pypkg and replace it with pkg cr_package_free(((_PackageObject *)pypkg)->package); ((_PackageObject *)pypkg)->package = pkg; ((_PackageObject *)pypkg)->free_on_destroy = free_on_destroy; ((_PackageObject *)pypkg)->parent = NULL; return pypkg; }
static void test_cr_db_dbinfo_update(TestData *testdata, G_GNUC_UNUSED gconstpointer test_data) { GError *err = NULL; gchar *path; cr_SqliteDb *db; cr_Package *pkg; // Create new db path = g_strconcat(testdata->tmp_dir, "/", TMP_PRIMARY_NAME, NULL); db = cr_db_open_primary(path, &err); g_assert(db); g_assert(!err); g_assert(g_file_test(path, G_FILE_TEST_EXISTS)); // Try cr_db_dbinfo_update cr_db_dbinfo_update(db, "foochecksum", &err); g_assert(!err); // Load package pkg = get_package(); // Add package cr_db_add_pkg(db, pkg, &err); g_assert(!err); // Try cr_db_dbinfo_update again cr_db_dbinfo_update(db, "foochecksum", &err); g_assert(!err); // Cleanup cr_package_free(pkg); g_free(path); cr_db_close(db, &err); g_assert(!err); }
static int package_init(_PackageObject *self, PyObject *args, PyObject *kwds) { char *kwlist[] = {NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "|:package_init", kwlist)) return -1; if (self->package && self->free_on_destroy) // reinitialization by __init__() cr_package_free(self->package); if (self->parent) { Py_DECREF(self->parent); self->parent = NULL; } self->package = cr_package_new(); if (self->package == NULL) { PyErr_SetString(CrErr_Exception, "Package initialization failed"); return -1; } return 0; }
void cr_free_values(gpointer data) { cr_package_free((cr_Package *) data); }
static int primary_pkgcb(cr_Package *pkg, void *cbdata, G_GNUC_UNUSED GError **err) { gboolean store_pkg = TRUE; cr_CbData *cb_data = cbdata; cr_Package *epkg; char *basename = cr_get_filename(pkg->location_href); assert(pkg); assert(pkg->pkgId); if (cb_data->chunk) { // Set pkg internal chunk to NULL, // if global chunk for all packages is used assert(pkg->chunk == cb_data->chunk); pkg->chunk = NULL; } if (cb_data->pkglist_ht && basename) { // If a pkglist was specified, // check if the package should be loaded or not store_pkg = g_hash_table_lookup_extended(cb_data->pkglist_ht, basename, NULL, NULL); } if (store_pkg) { // Check if pkgId is not on the list of blocked Ids if (g_hash_table_lookup_extended(cb_data->ignored_pkgIds, pkg->pkgId, NULL, NULL)) // We should ignore this pkgId (package's hash) store_pkg = FALSE; } if (!store_pkg) { // Drop the currently loaded package cr_package_free(pkg); return CR_CB_RET_OK; } epkg = g_hash_table_lookup(cb_data->ht, pkg->pkgId); if (!epkg) { // Store package into the hashtable pkg->loadingflags |= CR_PACKAGE_FROM_XML; pkg->loadingflags |= CR_PACKAGE_LOADED_PRI; g_hash_table_replace(cb_data->ht, pkg->pkgId, pkg); } else { // Package with the same pkgId (hash) already exists if (epkg->time_file == pkg->time_file && epkg->size_package == pkg->size_package && !g_strcmp0(cr_get_filename(pkg->location_href), basename)) { // The existing package is the same as the current one. // This is ok g_debug("Multiple packages with the same checksum: %s. " "Loading the info only once.", pkg->pkgId); } else { // The existing package is different. We have two different // packages with the same checksum -> drop both of them // and append this checksum to the ignored_pkgIds // XXX: Note that this constrain works only for single repo! // If the same cr_Metadata are loaded from several different // repos, than inter-repo packages with matching checksum // are not checked. g_debug("Multiple different packages (basename, mtime or size " "doesn't match) with the same checksum: %s. " "Ignoring all packages with the checksum.", pkg->pkgId); g_hash_table_remove(cb_data->ht, pkg->pkgId); g_hash_table_replace(cb_data->ignored_pkgIds, g_strdup(pkg->pkgId), NULL); } // Drop the currently loaded package cr_package_free(pkg); return CR_CB_RET_OK; } ++cb_data->pkgKey; pkg->pkgKey = cb_data->pkgKey; return CR_CB_RET_OK; }