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 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; }