From a04ef7ba1083665c9b3d5792eeebb88b8409ffc2 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 10 May 2012 08:50:37 -0400 Subject: [PATCH] core: Fix ostree-pull to be able to look up remotes in parent repo We should probably add a generalized inheritance mechanism. --- src/libostree/ostree-repo.c | 16 ++++++++++++++ src/libostree/ostree-repo.h | 2 ++ src/ostree/ostree-pull.c | 44 ++++++++++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index d13c0337..bbe8dc63 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -781,6 +781,22 @@ ostree_repo_get_mode (OstreeRepo *self) return priv->mode; } +/** + * ostree_repo_get_parent: + * @self: + * + * Before this function can be used, ostree_repo_init() must have been + * called. + * + * Returns: (transfer none): Parent repository, or %NULL if none + */ +OstreeRepo * +ostree_repo_get_parent (OstreeRepo *self) +{ + OstreeRepoPrivate *priv = GET_PRIVATE (self); + return priv->parent_repo; +} + GFile * ostree_repo_get_file_object_path (OstreeRepo *self, const char *checksum) diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index ea3fea0e..20154777 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -69,6 +69,8 @@ GKeyFile * ostree_repo_get_config (OstreeRepo *self); GKeyFile * ostree_repo_copy_config (OstreeRepo *self); +OstreeRepo * ostree_repo_get_parent (OstreeRepo *self); + gboolean ostree_repo_write_config (OstreeRepo *self, GKeyFile *new_config, GError **error); diff --git a/src/ostree/ostree-pull.c b/src/ostree/ostree-pull.c index 00c63afe..3534c19c 100644 --- a/src/ostree/ostree-pull.c +++ b/src/ostree/ostree-pull.c @@ -1062,7 +1062,46 @@ parse_ref_summary (const char *contents, g_strfreev (lines); return ret; } - + +static gboolean +repo_get_string_key_inherit (OstreeRepo *repo, + const char *section, + const char *key, + char **out_value, + GError **error) +{ + gboolean ret = FALSE; + GError *temp_error = NULL; + GKeyFile *config; + ot_lfree char *ret_value = NULL; + + config = ostree_repo_get_config (repo); + + ret_value = g_key_file_get_value (config, section, key, &temp_error); + if (temp_error) + { + OstreeRepo *parent = ostree_repo_get_parent (repo); + if (parent && + (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) + || g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND))) + { + g_clear_error (&temp_error); + if (!repo_get_string_key_inherit (parent, section, key, &ret_value, error)) + goto out; + } + else + { + g_propagate_error (error, temp_error); + goto out; + } + } + + ret = TRUE; + ot_transfer_out_value (out_value, &ret_value); + out: + return ret; +} + static gboolean ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error) { @@ -1118,8 +1157,7 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error) config = ostree_repo_get_config (repo); remote_key = g_strdup_printf ("remote \"%s\"", pull_data->remote_name); - baseurl = g_key_file_get_string (config, remote_key, "url", error); - if (!baseurl) + if (!repo_get_string_key_inherit (repo, remote_key, "url", &baseurl, error)) goto out; pull_data->base_uri = soup_uri_new (baseurl);