static int register_repo(config_repo_t *repo) { alpm_list_t *i; alpm_db_t *db; repo->siglevel = merge_siglevel(config->siglevel, repo->siglevel, repo->siglevel_mask); db = alpm_register_syncdb(config->handle, repo->name, repo->siglevel); if(db == NULL) { pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"), repo->name, alpm_strerror(alpm_errno(config->handle))); return 1; } pm_printf(ALPM_LOG_DEBUG, "setting usage of %d for %s repository\n", repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage, repo->name); alpm_db_set_usage(db, repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage); for(i = repo->servers; i; i = alpm_list_next(i)) { char *value = i->data; if(_add_mirror(db, value) != 0) { pm_printf(ALPM_LOG_ERROR, _("could not add mirror '%s' to database '%s' (%s)\n"), value, repo->name, alpm_strerror(alpm_errno(config->handle))); return 1; } } return 0; }
static alpm_handle_t *alpm_init(void) { alpm_handle_t *alpm = NULL; enum _alpm_errno_t alpm_errno = 0; FILE *fp; char line[PATH_MAX]; char *ptr, *section = NULL; alpm = alpm_initialize("/", "/var/lib/pacman", &alpm_errno); if (!alpm) { alpm_strerror(alpm_errno); return NULL; } db_local = alpm_get_localdb(alpm); fp = fopen("/etc/pacman.conf", "r"); if (!fp) { perror("fopen: /etc/pacman.conf"); return alpm; } while (fgets(line, PATH_MAX, fp)) { strtrim(line); if (strlen(line) == 0 || line[0] == '#') { continue; } if ((ptr = strchr(line, '#'))) { *ptr = '\0'; } if (line[0] == '[' && line[strlen(line) - 1] == ']') { ptr = &line[1]; if (section) { free(section); } section = strdup(ptr); section[strlen(section) - 1] = '\0'; if (strcmp(section, "options") != 0) { alpm_register_syncdb(alpm, section, 0); } } } free(section); fclose(fp); return alpm; }
/** Free the resources. * * @param ret the return value */ int ipacman_add_server(const char *name, const char *server) { alpm_db_t *db; db = alpm_register_syncdb(handle, name, ALPM_SIG_DATABASE_OPTIONAL); if(db == NULL) { printf("could not register '%s' database (%s)\n", name, alpm_strerror(alpm_errno(handle))); return 1; } if(alpm_db_add_server(db, server) != 0) { printf("could not add server URL to database '%s': %s (%s)\n", name, server, alpm_strerror(alpm_errno(handle))); return 1; } return 0; }
static void checkdbs(alpm_list_t *dbnames) { alpm_db_t *db = NULL; alpm_list_t *i; const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; for(i = dbnames; i; i = alpm_list_next(i)) { const char *dbname = i->data; db = alpm_register_syncdb(handle, dbname, level); if(db == NULL) { fprintf(stderr, "error: could not register sync database '%s' (%s)\n", dbname, alpm_strerror(alpm_errno(handle))); continue; } checkpkgs(alpm_db_get_pkgcache(db)); } }
static int expac_new(expac_t **expac, const char *config_file) { expac_t *e; enum _alpm_errno_t alpm_errno = 0; config_t config; const char *dbroot = "/"; const char *dbpath = "/var/lib/pacman"; int r; e = calloc(1, sizeof(*e)); if(e == NULL) { return -ENOMEM; } memset(&config, 0, sizeof(config)); r = config_parse(&config, config_file); if(r < 0) { return r; } if(config.dbpath) { dbpath = config.dbpath; } if(config.dbroot) { dbroot = config.dbroot; } e->alpm = alpm_initialize(dbroot, dbpath, &alpm_errno); if(!e->alpm) { return -alpm_errno; } for(int i = 0; i < config.size; ++i) { alpm_register_syncdb(e->alpm, config.repos[i], 0); } config_reset(&config); *expac = e; return 0; }
static int register_syncs(void) { FILE *fp; char *section = NULL; char line[LINE_MAX]; const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; fp = fopen(configfile, "r"); if(!fp) { fprintf(stderr, "error: config file %s could not be read\n", configfile); return 1; } while(fgets(line, LINE_MAX, fp)) { size_t linelen; char *ptr; /* ignore whole line and end of line comments */ if((ptr = strchr(line, '#'))) { *ptr = '\0'; } linelen = strtrim(line); if(linelen == 0) { continue; } if(line[0] == '[' && line[linelen - 1] == ']') { free(section); section = strndup(&line[1], linelen - 2); if(section && strcmp(section, "options") != 0) { alpm_db_t *db = alpm_register_syncdb(handle, section, level); alpm_db_set_usage(db, ALPM_DB_USAGE_ALL); } } } free(section); fclose(fp); return 0; }
static gboolean disabled_repos_configure (GHashTable *table, gboolean only_trusted, GError **error) { const alpm_list_t *i; g_return_val_if_fail (table != NULL, FALSE); g_return_val_if_fail (alpm != NULL, FALSE); if (alpm_unregister_all_syncdbs (alpm) < 0) { alpm_errno_t errno = alpm_errno (alpm); g_set_error_literal (error, ALPM_ERROR, errno, alpm_strerror (errno)); return FALSE; } for (i = configured; i != NULL; i = i->next) { PkBackendRepo *repo = (PkBackendRepo *) i->data; alpm_siglevel_t level = repo->level; alpm_db_t *db; if (g_hash_table_lookup (table, repo->name) != NULL) { /* repo is disabled */ continue; } else if (!only_trusted) { level &= ~ALPM_SIG_PACKAGE; level &= ~ALPM_SIG_DATABASE; level &= ~ALPM_SIG_USE_DEFAULT; } db = alpm_register_syncdb (alpm, repo->name, level); if (db == NULL) { alpm_errno_t errno = alpm_errno (alpm); g_set_error (error, ALPM_ERROR, errno, "[%s]: %s", repo->name, alpm_strerror (errno)); return FALSE; } alpm_db_set_servers (db, alpm_list_strdup (repo->servers)); } return TRUE; }
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_register_syncdb(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); }
/** * Wrap up a section once we have reached the end of it. This should be called * when a subsequent section is encountered, or when we have reached the end of * the root config file. Once called, all existing saved config pieces on the * section struct are freed. * @param section the current parsed and saved section data * @param parse_options whether we are parsing options or repo data * @return 0 on success, 1 on failure */ static int finish_section(struct section_t *section, int parse_options) { int ret = 0; alpm_list_t *i; alpm_db_t *db; pm_printf(ALPM_LOG_DEBUG, "config: finish section '%s'\n", section->name); /* parsing options (or nothing)- nothing to do except free the pieces */ if(!section->name || parse_options || section->is_options) { goto cleanup; } /* if we are not looking at options sections only, register a db */ db = alpm_register_syncdb(config->handle, section->name, section->siglevel); if(db == NULL) { pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"), section->name, alpm_strerror(alpm_errno(config->handle))); ret = 1; goto cleanup; } for(i = section->servers; i; i = alpm_list_next(i)) { char *value = i->data; if(_add_mirror(db, value) != 0) { pm_printf(ALPM_LOG_ERROR, _("could not add mirror '%s' to database '%s' (%s)\n"), value, section->name, alpm_strerror(alpm_errno(config->handle))); ret = 1; goto cleanup; } free(value); } cleanup: alpm_list_free(section->servers); section->servers = NULL; section->siglevel = ALPM_SIG_USE_DEFAULT; free(section->name); section->name = NULL; return ret; }
/** * call-seq: * register_syncdb( reponame , siglevel ) → a_database * * Registers a remote synchronisation database with libalpm. * * === Parameters * [reponame] * Name of the database/repository. That is, the name of the directory * on the synchronisation server. * [siglevel] * An array of one or more of the following values, denoting the security * level of the packages. * * :package * * :package_optional * * :package_marginal_ok * * :package_unknown_ok * * :database * * :database_optional * * :database_marginal_ok * * :database_unknown_ok * * :package_set * * :package_trust_set * * :use_default * * === Return value * The newly created Database instance. */ static VALUE register_syncdb(VALUE self, VALUE reponame, VALUE ary) { alpm_handle_t* p_alpm = NULL; alpm_siglevel_t level; alpm_db_t* p_db = NULL; VALUE obj; Data_Get_Struct(self, alpm_handle_t, p_alpm); level = siglevel_from_ruby(ary); p_db = alpm_register_syncdb(p_alpm, StringValuePtr(reponame), level); if (!p_db) { rb_raise(rb_eAlpm_Error, "Failed to register sync db with libalpm"); return Qnil; } obj = Data_Wrap_Struct(rb_cAlpm_Database, NULL, NULL, p_db); rb_iv_set(obj, "@alpm", self); return obj; }
static gboolean pk_alpm_disabled_repos_configure (PkBackend *backend, gboolean only_trusted, GError **error) { PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend); const alpm_list_t *i; if (alpm_unregister_all_syncdbs (priv->alpm) < 0) { alpm_errno_t errno = alpm_errno (priv->alpm); g_set_error_literal (error, PK_ALPM_ERROR, errno, alpm_strerror (errno)); return FALSE; } for (i = priv->configured_repos; i != NULL; i = i->next) { PkBackendRepo *repo = (PkBackendRepo *) i->data; alpm_siglevel_t level = repo->level; alpm_db_t *db; if (!only_trusted) { level &= ~ALPM_SIG_PACKAGE; level &= ~ALPM_SIG_DATABASE; level &= ~ALPM_SIG_USE_DEFAULT; } db = alpm_register_syncdb (priv->alpm, repo->name, level); if (db == NULL) { alpm_errno_t errno = alpm_errno (priv->alpm); g_set_error (error, PK_ALPM_ERROR, errno, "[%s]: %s", repo->name, alpm_strerror (errno)); return FALSE; } alpm_db_set_servers (db, alpm_list_strdup (repo->servers)); } return TRUE; }