/** * pacman_manager_register_sync_database: * @manager: A #PacmanManager. * @name: The name of the a sync database. * @error: A #GError, or %NULL. * * Searches for a sync database named @name, and registers a new one if none were found. * * Returns: A #PacmanDatabase, or %NULL if @error is set. */ PacmanDatabase *pacman_manager_register_sync_database (PacmanManager *manager, const gchar *name, GError **error) { PacmanDatabase *database; g_return_val_if_fail (manager != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); database = alpm_db_register_sync (name); if (database == NULL) { g_set_error (error, PACMAN_ERROR, pm_errno, _("Could not register database [%s]: %s"), name, alpm_strerrorlast ()); return NULL; } return database; }
/* @param reload set to > 0 if reloading libalpm so that cachedirs can be * reinitialized. */ static int setup_pacman_environment(int reload) { enum _alpm_errno_t err; alpm_list_t *i; if (reload) { pw_printf(PW_LOG_DEBUG, "Reloading pacman configuration\n"); pacman_cachedirs = NULL; } if (parse_pmconfig()) { /* Free cachedirs */ FREELIST(pacman_cachedirs); return error(PW_ERR_PM_CONF_PARSE); } if (!pacman_rootdir) { pacman_rootdir = xstrdup(PACMAN_DEF_ROOTDIR); } if (!pacman_dbpath) { pacman_dbpath = xstrdup(PACMAN_DEF_DBPATH); } if (!pacman_cachedirs) { pacman_cachedirs = alpm_list_add(pacman_cachedirs, xstrdup(PACMAN_DEF_CACHEDIR)); } alpm_option_set_cachedirs(config->handle, pacman_cachedirs); config->handle = alpm_initialize(pacman_rootdir, pacman_dbpath, &err); if (!config->handle) { return error(PW_ERR_INIT_ALPM_HANDLE); } /* Register sync dbs */ for (i = pacman_syncdbs; i; i = i->next) { if (!alpm_db_register_sync(config->handle, (const char *) i->data, ALPM_SIG_USE_DEFAULT)) { return error(PW_ERR_INIT_ALPM_REGISTER_SYNC); } } return 0; }
static PyObject* pyalpm_register_syncdb(PyObject *self, PyObject *args) { alpm_handle_t *handle = ALPM_HANDLE(self); const char *dbname; alpm_db_t *result; int pgp_level; if (!PyArg_ParseTuple(args, "si", &dbname, &pgp_level)) { PyErr_Format(PyExc_TypeError, "%s() takes a string and an integer", __func__); return NULL; } result = alpm_db_register_sync(handle, dbname, pgp_level); if (! result) { PyErr_Format(alpm_error, "unable to register sync database %s", dbname); return NULL; } return pyalpm_db_from_pmdb(result); }
/* Parse /etc/pacman.conf * We are hoping that the user does not remove the commented lines * under the [options] section. * * If there is insufficient information, we will fallback to the defaults. */ int parse_pmconfig(void) { int ret = 0; int len; FILE *fp; char buf[PATH_MAX]; char *line; int in_options = 0; int parsed_options = 0; fp = fopen(comstrs.pmconf, "r"); ASSERT(fp != NULL, RET_ERR(PW_ERR_PM_CONF_OPEN, -1)); pw_printf(PW_LOG_DEBUG, "%s : Parsing %s\n", __func__, comstrs.pmconf); while (line = fgets(buf, PATH_MAX, fp)) { line = strtrim(line); len = strlen(line); /* Ignore empty lines / Comments */ if (len == 0 || (!in_options && line[0] == '#')) { continue; } /* Entering a section */ if (line[0] == '[' && line[len-1] == ']') { line[len-1] = 0; ++line; line = strtrim(line); /* Get new length of line */ len = strlen(line); if (!strcmp(line, comstrs.opt)) { if (parsed_options) { pw_printf(PW_LOG_ERROR, "%sRepeated %s section in %s\n", comstrs.tab, comstrs.opt, comstrs.pmconf); ret = -1; goto cleanup; } pw_printf(PW_LOG_DEBUG, "%sParsing [%s] section of %s\n", comstrs.tab, comstrs.opt, comstrs.pmconf); parsed_options = 1; in_options = 1; continue; } else if (len == 0) { pw_printf(PW_LOG_DEBUG, "%sEmpty section in %s\n", comstrs.tab, comstrs.pmconf); ret = -1; goto cleanup; } else { /* Must be a repository * We just add the repository for now */ in_options = 0; pw_printf(PW_LOG_DEBUG, "%sParsing Repo [%s]\n", comstrs.tab, line); if (!alpm_db_register_sync(line)) { pw_printf(PW_LOG_ERROR, "%sFailed to register %s db\n", comstrs.tab, line); goto cleanup; } pw_printf(PW_LOG_DEBUG, "%sRegistering sync database '%s'\n", comstrs.tab, line); } } else if (in_options) { if (ret = _parse_pmoption(line)) { break; } continue; } } cleanup: fclose(fp); return ret; }