summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Conder <jonno.conder@gmail.com>2013-03-21 15:47:46 +1300
committerJonathan Conder <jonno.conder@gmail.com>2013-04-18 00:36:50 +1200
commit3f53fd273d0ca761a1101c3060d8ac8ded8aecf3 (patch)
tree360fa8692aa45cfce39cd0ca23424a17839394a7
parent6dabaa2e3c6b92bd2b5a609e0a8e4467c5e54f01 (diff)
alpm: improve and update config file parsing
-rw-r--r--backends/alpm/pk-backend-config.c531
-rw-r--r--backends/alpm/pk-backend-databases.c27
-rw-r--r--backends/alpm/pk-backend-databases.h6
-rw-r--r--backends/alpm/pk-backend-install.c2
4 files changed, 298 insertions, 268 deletions
diff --git a/backends/alpm/pk-backend-config.c b/backends/alpm/pk-backend-config.c
index faf47e62f..03adb4727 100644
--- a/backends/alpm/pk-backend-config.c
+++ b/backends/alpm/pk-backend-config.c
@@ -33,35 +33,32 @@
typedef struct
{
- gboolean checkspace, ilovecandy, totaldl, usedelta, usesyslog,
- verbosepkglists;
+ gboolean checkspace, color, ilovecandy, totaldl,
+ usesyslog, verbosepkglists;
+ gdouble deltaratio;
- gchar *arch, *cleanmethod, *dbpath, *gpgdir, *logfile, *root,
- *xfercmd;
+ gchar *arch, *cleanmethod, *dbpath, *gpgdir, *logfile,
+ *root, *xfercmd;
- alpm_list_t *cachedirs, *holdpkgs, *ignoregroups, *ignorepkgs,
- *noextracts, *noupgrades, *syncfirsts;
+ alpm_list_t *cachedirs, *holdpkgs, *ignoregroups,
+ *ignorepkgs, *localfilesiglevels, *noextracts,
+ *noupgrades, *remotefilesiglevels;
- alpm_list_t *repos;
- GHashTable *servers;
- GHashTable *levels;
- GRegex *xrepo, *xarch;
+ alpm_list_t *sections;
+ GRegex *xrepo, *xarch;
} PkBackendConfig;
+typedef struct
+{
+ gchar *name;
+ alpm_list_t *servers, *siglevels;
+} PkBackendConfigSection;
+
static PkBackendConfig *
pk_backend_config_new (void)
{
PkBackendConfig *config = g_new0 (PkBackendConfig, 1);
- alpm_siglevel_t *level = g_new0 (alpm_siglevel_t, 1);
-
- config->servers = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, NULL);
- config->levels = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
- g_free);
-
- *level |= ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL;
- *level |= ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
- g_hash_table_insert (config->levels, g_strdup ("options"), level);
+ config->deltaratio = 0.0;
config->xrepo = g_regex_new ("\\$repo", 0, 0, NULL);
config->xarch = g_regex_new ("\\$arch", 0, 0, NULL);
@@ -70,17 +67,17 @@ pk_backend_config_new (void)
}
static void
-pk_backend_config_list_free (alpm_list_t *list)
+pk_backend_config_section_free (gpointer data)
{
- alpm_list_free_inner (list, g_free);
- alpm_list_free (list);
-}
+ PkBackendConfigSection *section = data;
-static gboolean
-pk_backend_config_servers_free (gpointer repo, gpointer list, gpointer data)
-{
- pk_backend_config_list_free ((alpm_list_t *) list);
- return TRUE;
+ if (section != NULL) {
+ g_free (section->name);
+ alpm_list_free_inner (section->servers, g_free);
+ alpm_list_free (section->servers);
+ FREELIST (section->siglevels);
+ g_free (section);
+ }
}
static void
@@ -100,15 +97,13 @@ pk_backend_config_free (PkBackendConfig *config)
FREELIST (config->holdpkgs);
FREELIST (config->ignoregroups);
FREELIST (config->ignorepkgs);
+ FREELIST (config->localfilesiglevels);
FREELIST (config->noextracts);
FREELIST (config->noupgrades);
- FREELIST (config->syncfirsts);
+ FREELIST (config->remotefilesiglevels);
- pk_backend_config_list_free (config->repos);
- g_hash_table_foreach_remove (config->servers,
- pk_backend_config_servers_free, NULL);
- g_hash_table_unref (config->servers);
- g_hash_table_unref (config->levels);
+ alpm_list_free_inner (config->sections, pk_backend_config_section_free);
+ alpm_list_free (config->sections);
g_regex_unref (config->xrepo);
g_regex_unref (config->xarch);
@@ -123,6 +118,14 @@ pk_backend_config_set_checkspace (PkBackendConfig *config)
}
static void
+pk_backend_config_set_color (PkBackendConfig *config)
+{
+ g_return_if_fail (config != NULL);
+
+ config->color = TRUE;
+}
+
+static void
pk_backend_config_set_ilovecandy (PkBackendConfig *config)
{
g_return_if_fail (config != NULL);
@@ -143,7 +146,7 @@ pk_backend_config_set_usedelta (PkBackendConfig *config)
{
g_return_if_fail (config != NULL);
- config->usedelta = TRUE;
+ config->deltaratio = 0.7;
}
static void
@@ -171,6 +174,7 @@ typedef struct
/* keep this in alphabetical order */
static const PkBackendConfigBoolean pk_backend_config_boolean_options[] = {
{ "CheckSpace", pk_backend_config_set_checkspace },
+ { "Color", pk_backend_config_set_color },
{ "ILoveCandy", pk_backend_config_set_ilovecandy },
{ "TotalDownload", pk_backend_config_set_totaldl },
{ "UseDelta", pk_backend_config_set_usedelta },
@@ -284,6 +288,22 @@ pk_backend_config_set_root (PkBackendConfig *config, const gchar *path)
}
static void
+pk_backend_config_set_deltaratio (PkBackendConfig *config, const gchar *number)
+{
+ gdouble ratio;
+ gchar *endptr;
+
+ g_return_if_fail (config != NULL);
+ g_return_if_fail (number != NULL);
+
+ ratio = g_ascii_strtod (number, &endptr);
+ /* this ignores invalid values whereas pacman reports an error */
+ if (*endptr == '\0' && 0.0 <= ratio && ratio <= 2.0) {
+ config->deltaratio = ratio;
+ }
+}
+
+static void
pk_backend_config_set_xfercmd (PkBackendConfig *config, const gchar *command)
{
g_return_if_fail (config != NULL);
@@ -308,6 +328,7 @@ static const PkBackendConfigString pk_backend_config_string_options[] = {
{ "GPGDir", pk_backend_config_set_gpgdir },
{ "LogFile", pk_backend_config_set_logfile },
{ "RootDir", pk_backend_config_set_root },
+ { "UseDelta", pk_backend_config_set_deltaratio },
{ "XferCommand", pk_backend_config_set_xfercmd },
{ NULL, NULL }
};
@@ -335,102 +356,51 @@ pk_backend_config_set_string (PkBackendConfig *config, const gchar *option,
}
}
-static void
-pk_backend_config_add_holdpkg (PkBackendConfig *config, gchar *package)
-{
- g_return_if_fail (config != NULL);
- g_return_if_fail (package != NULL);
-
- config->holdpkgs = alpm_list_add (config->holdpkgs, package);
-}
-
-static void
-pk_backend_config_add_ignoregroup (PkBackendConfig *config, gchar *group)
-{
- g_return_if_fail (config != NULL);
- g_return_if_fail (group != NULL);
-
- config->ignoregroups = alpm_list_add (config->ignoregroups, group);
-}
-
-static void
-pk_backend_config_add_ignorepkg (PkBackendConfig *config, gchar *package)
-{
- g_return_if_fail (config != NULL);
- g_return_if_fail (package != NULL);
-
- config->ignorepkgs = alpm_list_add (config->ignorepkgs, package);
-}
-
-static void
-pk_backend_config_add_noextract (PkBackendConfig *config, gchar *filename)
-{
- g_return_if_fail (config != NULL);
- g_return_if_fail (filename != NULL);
-
- config->noextracts = alpm_list_add (config->noextracts, filename);
-}
-
-static void
-pk_backend_config_add_noupgrade (PkBackendConfig *config, gchar *filename)
-{
- g_return_if_fail (config != NULL);
- g_return_if_fail (filename != NULL);
-
- config->noupgrades = alpm_list_add (config->noupgrades, filename);
-}
-
-static void
-pk_backend_config_add_syncfirst (PkBackendConfig *config, gchar *package)
-{
- g_return_if_fail (config != NULL);
- g_return_if_fail (package != NULL);
-
- config->syncfirsts = alpm_list_add (config->syncfirsts, package);
-}
-
typedef struct
{
const gchar *name;
- void (*func) (PkBackendConfig *config, gchar *value);
+ glong offset;
} PkBackendConfigList;
/* keep this in alphabetical order */
static const PkBackendConfigList pk_backend_config_list_options[] = {
- { "HoldPkg", pk_backend_config_add_holdpkg },
- { "IgnoreGroup", pk_backend_config_add_ignoregroup },
- { "IgnorePkg", pk_backend_config_add_ignorepkg },
- { "NoExtract", pk_backend_config_add_noextract },
- { "NoUpgrade", pk_backend_config_add_noupgrade },
- { "SyncFirst", pk_backend_config_add_syncfirst },
- { NULL, NULL }
+ { "HoldPkg", G_STRUCT_OFFSET (PkBackendConfig, holdpkgs) },
+ { "IgnoreGroup", G_STRUCT_OFFSET (PkBackendConfig, ignoregroups) },
+ { "IgnorePkg", G_STRUCT_OFFSET (PkBackendConfig, ignorepkgs) },
+ { "LocalFileSigLevel", G_STRUCT_OFFSET (PkBackendConfig,
+ localfilesiglevels) },
+ { "NoExtract", G_STRUCT_OFFSET (PkBackendConfig, noextracts) },
+ { "NoUpgrade", G_STRUCT_OFFSET (PkBackendConfig, noupgrades) },
+ { "RemoteFileSigLevel", G_STRUCT_OFFSET (PkBackendConfig,
+ remotefilesiglevels) },
+ { NULL, 0 }
};
-static void
-pk_backend_config_list_add (PkBackendConfig *config, gsize option,
- const gchar *list)
+static alpm_list_t *
+alpm_list_add_words (alpm_list_t *list, const gchar *words)
{
gchar *str;
- for (str = strchr (list, ' '); str != NULL; str = strchr (list, ' ')) {
+ while ((str = strchr (words, ' ')) != NULL) {
/* allocate normally */
- gchar *value = malloc ((++str - list) * sizeof (gchar));
- g_strlcpy (value, list, str - list);
- pk_backend_config_list_options[option].func (config, value);
- list = str;
+ gchar *word = malloc ((++str - words) * sizeof (gchar));
+ g_strlcpy (word, words, str - words);
+ list = alpm_list_add (list, word);
+ words = str;
}
- pk_backend_config_list_options[option].func (config, strdup (list));
+
+ return alpm_list_add (list, strdup (words));
}
static gboolean
pk_backend_config_set_list (PkBackendConfig *config, const gchar *option,
- const gchar *list)
+ const gchar *words)
{
gsize i;
g_return_val_if_fail (config != NULL, FALSE);
g_return_val_if_fail (option != NULL, FALSE);
- g_return_val_if_fail (list != NULL, FALSE);
+ g_return_val_if_fail (words != NULL, FALSE);
for (i = 0;; ++i) {
const gchar *name = pk_backend_config_list_options[i].name;
@@ -439,37 +409,57 @@ pk_backend_config_set_list (PkBackendConfig *config, const gchar *option,
if (name == NULL || cmp < 0) {
return FALSE;
} else if (cmp == 0) {
- pk_backend_config_list_add (config, i, list);
+ glong offset = pk_backend_config_list_options[i].offset;
+ alpm_list_t **list = G_STRUCT_MEMBER_P (config, offset);
+ *list = alpm_list_add_words (*list, words);
return TRUE;
}
}
}
-static void
-pk_backend_config_add_repo (PkBackendConfig *config, const gchar *repo)
+static gint
+pk_backend_config_section_match (gconstpointer element, gconstpointer name)
{
- g_return_if_fail (config != NULL);
- g_return_if_fail (repo != NULL);
+ const PkBackendConfigSection *section = element;
+
+ g_return_val_if_fail (section != NULL, -1);
+
+ return g_strcmp0 (section->name, name);
+}
- if (alpm_list_find_str (config->repos, repo) == NULL) {
- config->repos = alpm_list_add (config->repos, g_strdup (repo));
+static PkBackendConfigSection *
+pk_backend_config_enter_section (PkBackendConfig *config, const gchar *name)
+{
+ PkBackendConfigSection *section;
+
+ g_return_val_if_fail (config != NULL, NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
+ section = alpm_list_find (config->sections, name,
+ pk_backend_config_section_match);
+ if (section != NULL) {
+ return section;
}
+
+ section = g_new0 (PkBackendConfigSection, 1);
+ section->name = g_strdup (name);
+ config->sections = alpm_list_add (config->sections, section);
+ return section;
}
static gboolean
-pk_backend_config_repo_add_server (PkBackendConfig *config, const gchar *repo,
- const gchar *value, GError **e)
+pk_backend_config_add_server (PkBackendConfig *config,
+ PkBackendConfigSection *section,
+ const gchar *address, GError **e)
{
- alpm_list_t *list;
gchar *url;
g_return_val_if_fail (config != NULL, FALSE);
- g_return_val_if_fail (repo != NULL, FALSE);
- g_return_val_if_fail (alpm_list_find_str (config->repos, repo) != NULL,
- FALSE);
- g_return_val_if_fail (value != NULL, FALSE);
+ g_return_val_if_fail (section != NULL, FALSE);
+ g_return_val_if_fail (address != NULL, FALSE);
- url = g_regex_replace_literal (config->xrepo, value, -1, 0, repo, 0, e);
+ url = g_regex_replace_literal (config->xrepo, address, -1, 0,
+ section->name, 0, e);
if (url == NULL) {
return FALSE;
}
@@ -488,105 +478,26 @@ pk_backend_config_repo_add_server (PkBackendConfig *config, const gchar *repo,
"url contained $arch, which is not set");
}
- list = (alpm_list_t *) g_hash_table_lookup (config->servers, repo);
- list = alpm_list_add (list, url);
- g_hash_table_insert (config->servers, g_strdup (repo), list);
+ section->servers = alpm_list_add (section->servers, url);
return TRUE;
}
-static gboolean
-pk_backend_config_set_siglevel (PkBackendConfig *config, const gchar *section,
- const gchar *list, GError **error)
+static void
+pk_backend_config_add_siglevel (PkBackendConfig *config,
+ PkBackendConfigSection *section,
+ const gchar *words)
{
- alpm_siglevel_t *level;
-
- g_return_val_if_fail (config != NULL, FALSE);
- g_return_val_if_fail (section != NULL, FALSE);
- g_return_val_if_fail (list != NULL, FALSE);
-
- level = g_hash_table_lookup (config->levels, section);
- if (level == NULL) {
- level = g_hash_table_lookup (config->levels, "options");
- level = g_memdup (level, sizeof (alpm_siglevel_t));
- g_hash_table_insert (config->levels, g_strdup (section), level);
- }
-
- while (TRUE) {
- gboolean package = TRUE, database = TRUE;
-
- if (g_str_has_prefix (list, "Package")) {
- database = FALSE;
- list += 7;
- } else if (g_str_has_prefix (list, "Database")) {
- package = FALSE;
- list += 8;
- }
-
- /* this also allows e.g. NeverEver, so put prefixes last */
- if (g_str_has_prefix (list, "Never")) {
- if (package) {
- *level &= ~ALPM_SIG_PACKAGE;
- }
- if (database) {
- *level &= ~ALPM_SIG_DATABASE;
- }
- } else if (g_str_has_prefix (list, "Optional")) {
- if (package) {
- *level |= ALPM_SIG_PACKAGE;
- *level |= ALPM_SIG_PACKAGE_OPTIONAL;
- }
- if (database) {
- *level |= ALPM_SIG_DATABASE;
- *level |= ALPM_SIG_DATABASE_OPTIONAL;
- }
- } else if (g_str_has_prefix (list, "Required")) {
- if (package) {
- *level |= ALPM_SIG_PACKAGE;
- *level &= ~ALPM_SIG_PACKAGE_OPTIONAL;
- }
- if (database) {
- *level |= ALPM_SIG_DATABASE;
- *level &= ~ALPM_SIG_DATABASE_OPTIONAL;
- }
- } else if (g_str_has_prefix (list, "TrustedOnly")) {
- if (package) {
- *level &= ~ALPM_SIG_PACKAGE_MARGINAL_OK;
- *level &= ~ALPM_SIG_PACKAGE_UNKNOWN_OK;
- }
- if (database) {
- *level &= ~ALPM_SIG_DATABASE_MARGINAL_OK;
- *level &= ~ALPM_SIG_DATABASE_UNKNOWN_OK;
- }
- } else if (g_str_has_prefix (list, "TrustAll")) {
- if (package) {
- *level |= ALPM_SIG_PACKAGE_MARGINAL_OK;
- *level |= ALPM_SIG_PACKAGE_UNKNOWN_OK;
- }
- if (database) {
- *level |= ALPM_SIG_DATABASE_MARGINAL_OK;
- *level |= ALPM_SIG_DATABASE_UNKNOWN_OK;
- }
- } else {
- g_set_error (error, ALPM_ERROR, ALPM_ERR_CONFIG_INVALID,
- "invalid SigLevel value: %s", list);
- return FALSE;
- }
-
- list = strchr (list, ' ');
- if (list == NULL) {
- break;
- } else {
- ++list;
- }
- }
+ g_return_if_fail (config != NULL);
+ g_return_if_fail (section != NULL);
+ g_return_if_fail (words != NULL);
- return TRUE;
+ section->siglevels = alpm_list_add_words (section->siglevels, words);
}
static gboolean
pk_backend_config_parse (PkBackendConfig *config, const gchar *filename,
- gchar *section, GError **error)
+ PkBackendConfigSection *section, GError **error)
{
GFile *file;
GFileInputStream *is;
@@ -610,7 +521,6 @@ pk_backend_config_parse (PkBackendConfig *config, const gchar *filename,
}
input = g_data_input_stream_new (G_INPUT_STREAM (is));
- section = g_strdup (section);
for (;; g_free (line), ++num) {
line = g_data_input_stream_read_line (input, NULL, NULL, &e);
@@ -642,13 +552,7 @@ pk_backend_config_parse (PkBackendConfig *config, const gchar *filename,
break;
}
- g_free (section);
- section = g_strdup (str);
-
- if (g_strcmp0 (section, "options") != 0) {
- pk_backend_config_add_repo (config, section);
- }
-
+ section = pk_backend_config_enter_section (config, str);
continue;
}
@@ -668,7 +572,8 @@ pk_backend_config_parse (PkBackendConfig *config, const gchar *filename,
if (str == NULL) {
/* set a boolean directive */
- if (g_strcmp0 (section, "options") == 0 &&
+ if (pk_backend_config_section_match (section,
+ "options") == 0 &&
pk_backend_config_set_boolean (config, key)) {
continue;
}
@@ -697,7 +602,8 @@ pk_backend_config_parse (PkBackendConfig *config, const gchar *filename,
} else {
continue;
}
- } else if (g_strcmp0 (section, "options") == 0) {
+ } else if (pk_backend_config_section_match (section,
+ "options") == 0) {
/* set a string or list directive */
if (pk_backend_config_set_string (config, key, str) ||
pk_backend_config_set_list (config, key, str)) {
@@ -705,8 +611,8 @@ pk_backend_config_parse (PkBackendConfig *config, const gchar *filename,
}
/* report error below */
} else if (g_strcmp0 (key, "Server") == 0) {
- if (!pk_backend_config_repo_add_server (config, section,
- str, &e)) {
+ if (!pk_backend_config_add_server (config, section,
+ str, &e)) {
break;
} else {
continue;
@@ -714,12 +620,8 @@ pk_backend_config_parse (PkBackendConfig *config, const gchar *filename,
}
if (g_strcmp0 (key, "SigLevel") == 0 && str != NULL) {
- if (!pk_backend_config_set_siglevel (config, section,
- str, &e)) {
- break;
- } else {
- continue;
- }
+ pk_backend_config_add_siglevel (config, section, str);
+ continue;
}
/* report errors from above */
@@ -728,8 +630,6 @@ pk_backend_config_parse (PkBackendConfig *config, const gchar *filename,
break;
}
- g_free (section);
-
g_object_unref (input);
g_object_unref (is);
g_object_unref (file);
@@ -817,11 +717,160 @@ pk_backend_config_initialize_alpm (PkBackendConfig *config, GError **error)
return handle;
}
+static alpm_siglevel_t
+alpm_siglevel_parse (alpm_siglevel_t base, const alpm_list_t *list,
+ GError **error)
+{
+ for (; list != NULL; list = list->next) {
+ gboolean package = TRUE, database = TRUE;
+ const gchar *level = (const gchar *) list->data;
+
+ if (g_str_has_prefix (level, "Package")) {
+ database = FALSE;
+ level += 7;
+ } else if (g_str_has_prefix (level, "Database")) {
+ package = FALSE;
+ level += 8;
+ }
+
+ if (g_strcmp0 (level, "Never") == 0) {
+ if (package) {
+ base &= ~ALPM_SIG_PACKAGE;
+ base |= ALPM_SIG_PACKAGE_SET;
+ }
+ if (database) {
+ base &= ~ALPM_SIG_DATABASE;
+ }
+ } else if (g_strcmp0 (level, "Optional") == 0) {
+ if (package) {
+ base |= ALPM_SIG_PACKAGE;
+ base |= ALPM_SIG_PACKAGE_OPTIONAL;
+ base |= ALPM_SIG_PACKAGE_SET;
+ }
+ if (database) {
+ base |= ALPM_SIG_DATABASE;
+ base |= ALPM_SIG_DATABASE_OPTIONAL;
+ }
+ } else if (g_strcmp0 (level, "Required") == 0) {
+ if (package) {
+ base |= ALPM_SIG_PACKAGE;
+ base &= ~ALPM_SIG_PACKAGE_OPTIONAL;
+ base |= ALPM_SIG_PACKAGE_SET;
+ }
+ if (database) {
+ base |= ALPM_SIG_DATABASE;
+ base &= ~ALPM_SIG_DATABASE_OPTIONAL;
+ }
+ } else if (g_strcmp0 (level, "TrustedOnly") == 0) {
+ if (package) {
+ base &= ~ALPM_SIG_PACKAGE_MARGINAL_OK;
+ base &= ~ALPM_SIG_PACKAGE_UNKNOWN_OK;
+ base |= ALPM_SIG_PACKAGE_TRUST_SET;
+ }
+ if (database) {
+ base &= ~ALPM_SIG_DATABASE_MARGINAL_OK;
+ base &= ~ALPM_SIG_DATABASE_UNKNOWN_OK;
+ }
+ } else if (g_strcmp0 (level, "TrustAll") == 0) {
+ if (package) {
+ base |= ALPM_SIG_PACKAGE_MARGINAL_OK;
+ base |= ALPM_SIG_PACKAGE_UNKNOWN_OK;
+ base |= ALPM_SIG_PACKAGE_TRUST_SET;
+ }
+ if (database) {
+ base |= ALPM_SIG_DATABASE_MARGINAL_OK;
+ base |= ALPM_SIG_DATABASE_UNKNOWN_OK;
+ }
+ } else {
+ g_set_error (error, ALPM_ERROR, ALPM_ERR_CONFIG_INVALID,
+ "invalid SigLevel value: %s", level);
+ return ALPM_SIG_USE_DEFAULT;
+ }
+ }
+
+ return base;
+}
+
+static alpm_siglevel_t
+alpm_siglevel_cross (alpm_siglevel_t base, const alpm_list_t *list,
+ GError **error)
+{
+ alpm_siglevel_t level;
+
+ if (list == NULL) {
+ return base;
+ }
+
+ level = alpm_siglevel_parse (0, list, error);
+ if (level == ALPM_SIG_USE_DEFAULT) {
+ return level;
+ }
+
+ /* based on unexplained code in pacman */
+ if ((level & ALPM_SIG_PACKAGE_SET) == 0) {
+ level |= base & (ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL);
+ }
+ if ((level & ALPM_SIG_PACKAGE_TRUST_SET) == 0) {
+ level |= base & (ALPM_SIG_PACKAGE_MARGINAL_OK |
+ ALPM_SIG_PACKAGE_UNKNOWN_OK);
+ }
+
+ return level;
+}
+
+static gboolean
+pk_backend_config_configure_repos (PkBackendConfig *config,
+ alpm_handle_t *handle, GError **error)
+{
+ alpm_siglevel_t base, local, remote;
+ const alpm_list_t *i;
+ PkBackendConfigSection *options;
+
+ g_return_val_if_fail (config != NULL, FALSE);
+
+ base = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL |
+ ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
+
+ i = config->sections;
+ options = i->data;
+
+ base = alpm_siglevel_parse (base, options->siglevels, error);
+ if (base == ALPM_SIG_USE_DEFAULT) {
+ return FALSE;
+ }
+
+ local = alpm_siglevel_cross (base, config->localfilesiglevels, error);
+ if (local == ALPM_SIG_USE_DEFAULT) {
+ return FALSE;
+ }
+
+ remote = alpm_siglevel_cross (base, config->remotefilesiglevels, error);
+ if (remote == ALPM_SIG_USE_DEFAULT) {
+ return FALSE;
+ }
+
+ alpm_option_set_default_siglevel (handle, base);
+ alpm_option_set_local_file_siglevel (handle, local);
+ alpm_option_set_remote_file_siglevel (handle, remote);
+
+ while ((i = i->next) != NULL) {
+ PkBackendConfigSection *repo = i->data;
+ alpm_siglevel_t level;
+
+ level = alpm_siglevel_parse (base, repo->siglevels, error);
+ if (level == ALPM_SIG_USE_DEFAULT) {
+ return FALSE;
+ }
+ pk_backend_add_database (repo->name, repo->servers, level);
+ }
+
+ return TRUE;
+}
+
static alpm_handle_t *
pk_backend_config_configure_alpm (PkBackendConfig *config, GError **error)
{
alpm_handle_t *handle;
- alpm_siglevel_t *level;
g_return_val_if_fail (config != NULL, FALSE);
@@ -831,12 +880,9 @@ pk_backend_config_configure_alpm (PkBackendConfig *config, GError **error)
}
alpm_option_set_checkspace (handle, config->checkspace);
- alpm_option_set_usedelta (handle, config->usedelta);
alpm_option_set_usesyslog (handle, config->usesyslog);
alpm_option_set_arch (handle, config->arch);
-
- level = g_hash_table_lookup (config->levels, "options");
- alpm_option_set_default_siglevel (handle, *level);
+ alpm_option_set_deltaratio (handle, config->deltaratio);
/* backend takes ownership */
g_free (xfercmd);
@@ -854,11 +900,6 @@ pk_backend_config_configure_alpm (PkBackendConfig *config, GError **error)
holdpkgs = config->holdpkgs;
config->holdpkgs = NULL;
- /* backend takes ownership */
- FREELIST (syncfirsts);
- syncfirsts = config->syncfirsts;
- config->syncfirsts = NULL;
-
/* alpm takes ownership */
alpm_option_set_ignoregroups (handle, config->ignoregroups);
config->ignoregroups = NULL;
@@ -875,8 +916,7 @@ pk_backend_config_configure_alpm (PkBackendConfig *config, GError **error)
alpm_option_set_noupgrades (handle, config->noupgrades);
config->noupgrades = NULL;
- pk_backend_configure_repos (config->repos, config->servers,
- config->levels);
+ pk_backend_config_configure_repos (config, handle, error);
return handle;
}
@@ -892,6 +932,7 @@ pk_backend_configure (const gchar *filename, GError **error)
g_debug ("reading config from %s", filename);
config = pk_backend_config_new ();
+ pk_backend_config_enter_section (config, "options");
if (pk_backend_config_parse (config, filename, NULL, &e)) {
handle = pk_backend_config_configure_alpm (config, &e);
diff --git a/backends/alpm/pk-backend-databases.c b/backends/alpm/pk-backend-databases.c
index 09462ab4b..09d5a73c5 100644
--- a/backends/alpm/pk-backend-databases.c
+++ b/backends/alpm/pk-backend-databases.c
@@ -176,29 +176,18 @@ disabled_repos_configure (GHashTable *table, gboolean only_trusted,
}
void
-pk_backend_configure_repos (alpm_list_t *repos, GHashTable *servers,
- GHashTable *levels)
+pk_backend_add_database (const gchar *name, alpm_list_t *servers,
+ alpm_siglevel_t level)
{
- alpm_list_t *i;
-
- g_return_if_fail (servers != NULL);
-
- for (i = repos; i != NULL; i = i->next) {
- PkBackendRepo *repo = g_new (PkBackendRepo, 1);
- gpointer value = g_hash_table_lookup (servers, i->data);
+ PkBackendRepo *repo = g_new (PkBackendRepo, 1);
- repo->name = g_strdup ((const gchar *) i->data);
- repo->servers = alpm_list_strdup ((alpm_list_t *) value);
+ g_return_if_fail (name != NULL);
- value = g_hash_table_lookup (levels, i->data);
- if (value != NULL) {
- repo->level = *(alpm_siglevel_t *) value;
- } else {
- repo->level = ALPM_SIG_USE_DEFAULT;
- }
+ repo->name = g_strdup (name);
+ repo->servers = alpm_list_strdup (servers);
+ repo->level = level;
- configured = alpm_list_add (configured, repo);
- }
+ configured = alpm_list_add (configured, repo);
}
gboolean
diff --git a/backends/alpm/pk-backend-databases.h b/backends/alpm/pk-backend-databases.h
index d9b9e7861..d0dbb7c9c 100644
--- a/backends/alpm/pk-backend-databases.h
+++ b/backends/alpm/pk-backend-databases.h
@@ -24,9 +24,9 @@
#include <alpm.h>
#include <pk-backend.h>
-void pk_backend_configure_repos (alpm_list_t *repos,
- GHashTable *servers,
- GHashTable *levels);
+void pk_backend_add_database (const gchar *name,
+ alpm_list_t *servers,
+ alpm_siglevel_t level);
gboolean pk_backend_disable_signatures (PkBackend *self,
GError **error);
diff --git a/backends/alpm/pk-backend-install.c b/backends/alpm/pk-backend-install.c
index 393c4ae40..0b036f3ec 100644
--- a/backends/alpm/pk-backend-install.c
+++ b/backends/alpm/pk-backend-install.c
@@ -39,7 +39,7 @@ alpm_add_file (const gchar *filename)
g_return_val_if_fail (filename != NULL, -1);
g_return_val_if_fail (alpm != NULL, -1);
- level = alpm_option_get_default_siglevel (alpm);
+ level = alpm_option_get_local_file_siglevel (alpm);
if (alpm_pkg_load (alpm, filename, 1, level, &pkg) < 0) {
return -1;