repo: merge repo_remote_fetch_summary_{metalink,url}
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
133fb5ffdc
commit
783e83c62c
|
|
@ -1671,89 +1671,7 @@ out:
|
|||
}
|
||||
|
||||
static gboolean
|
||||
repo_remote_fetch_summary_url (OstreeRepo *self,
|
||||
const char *name,
|
||||
GBytes **out_summary,
|
||||
GBytes **out_signatures,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
glnx_unref_object OstreeFetcher *fetcher = NULL;
|
||||
g_autoptr(GMainLoop) main_loop = NULL;
|
||||
g_autofree char *url_string = NULL;
|
||||
SoupURI *base_uri = NULL;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if (!ostree_repo_remote_get_url (self, name, &url_string, error))
|
||||
goto out;
|
||||
|
||||
base_uri = soup_uri_new (url_string);
|
||||
|
||||
if (base_uri == NULL)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Invalid URL '%s'", url_string);
|
||||
goto out;
|
||||
}
|
||||
|
||||
fetcher = _ostree_repo_remote_new_fetcher (self, name, error);
|
||||
|
||||
if (fetcher == NULL)
|
||||
goto out;
|
||||
|
||||
main_loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
|
||||
|
||||
{
|
||||
SoupURI *uri;
|
||||
const char *base_path;
|
||||
g_autofree char *path = NULL;
|
||||
|
||||
base_path = soup_uri_get_path (base_uri);
|
||||
path = g_build_filename (base_path, "summary", NULL);
|
||||
uri = soup_uri_new_with_base (base_uri, path);
|
||||
|
||||
ret = _ostree_fetcher_request_uri_to_membuf (fetcher, uri,
|
||||
FALSE, TRUE,
|
||||
out_summary,
|
||||
main_loop,
|
||||
OSTREE_MAX_METADATA_SIZE,
|
||||
cancellable, error);
|
||||
soup_uri_free (uri);
|
||||
|
||||
if (!ret)
|
||||
goto out;
|
||||
}
|
||||
|
||||
{
|
||||
SoupURI *uri;
|
||||
const char *base_path;
|
||||
g_autofree char *path = NULL;
|
||||
|
||||
base_path = soup_uri_get_path (base_uri);
|
||||
path = g_build_filename (base_path, "summary.sig", NULL);
|
||||
uri = soup_uri_new_with_base (base_uri, path);
|
||||
|
||||
ret = _ostree_fetcher_request_uri_to_membuf (fetcher, uri,
|
||||
FALSE, TRUE,
|
||||
out_signatures,
|
||||
main_loop,
|
||||
OSTREE_MAX_METADATA_SIZE,
|
||||
cancellable, error);
|
||||
soup_uri_free (uri);
|
||||
|
||||
if (!ret)
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
if (base_uri != NULL)
|
||||
soup_uri_free (base_uri);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
repo_remote_fetch_summary_metalink (OstreeRepo *self,
|
||||
repo_remote_fetch_summary (OstreeRepo *self,
|
||||
const char *name,
|
||||
const char *metalink_url_string,
|
||||
GBytes **out_summary,
|
||||
|
|
@ -1763,41 +1681,59 @@ repo_remote_fetch_summary_metalink (OstreeRepo *self,
|
|||
{
|
||||
glnx_unref_object OstreeFetcher *fetcher = NULL;
|
||||
g_autoptr(GMainLoop) main_loop = NULL;
|
||||
SoupURI *metalink_uri = NULL;
|
||||
gboolean ret = FALSE;
|
||||
SoupURI *base_uri = NULL;
|
||||
uint i;
|
||||
|
||||
metalink_uri = soup_uri_new (metalink_url_string);
|
||||
|
||||
if (metalink_uri == NULL)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Invalid URL '%s'", metalink_url_string);
|
||||
goto out;
|
||||
}
|
||||
|
||||
fetcher = _ostree_repo_remote_new_fetcher (self, name, error);
|
||||
|
||||
if (fetcher == NULL)
|
||||
goto out;
|
||||
const char *filenames[] = {"summary", "summary.sig"};
|
||||
GBytes **outputs[] = {out_summary, out_signatures};
|
||||
|
||||
main_loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
|
||||
|
||||
fetcher = _ostree_repo_remote_new_fetcher (self, name, error);
|
||||
if (fetcher == NULL)
|
||||
goto out;
|
||||
|
||||
base_uri = soup_uri_new (metalink_url_string);
|
||||
|
||||
{
|
||||
g_autofree char *url_string = NULL;
|
||||
if (metalink_url_string)
|
||||
url_string = g_strdup (metalink_url_string);
|
||||
else
|
||||
{
|
||||
if (!ostree_repo_remote_get_url (self, name, &url_string, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
base_uri = soup_uri_new (url_string);
|
||||
if (base_uri == NULL)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Invalid URL '%s'", url_string);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (filenames); i++)
|
||||
{
|
||||
if (metalink_url_string)
|
||||
{
|
||||
glnx_unref_object OstreeMetalink *metalink = NULL;
|
||||
GError *local_error = NULL;
|
||||
|
||||
metalink = _ostree_metalink_new (fetcher, "summary",
|
||||
metalink = _ostree_metalink_new (fetcher, filenames[i],
|
||||
OSTREE_MAX_METADATA_SIZE,
|
||||
metalink_uri);
|
||||
base_uri);
|
||||
|
||||
_ostree_metalink_request_sync (metalink, main_loop,
|
||||
NULL, out_summary, NULL,
|
||||
NULL, outputs[i], NULL,
|
||||
cancellable, &local_error);
|
||||
|
||||
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||
{
|
||||
g_clear_error (&local_error);
|
||||
*out_summary = NULL;
|
||||
*outputs[i] = NULL;
|
||||
}
|
||||
else if (local_error != NULL)
|
||||
{
|
||||
|
|
@ -1805,36 +1741,34 @@ repo_remote_fetch_summary_metalink (OstreeRepo *self,
|
|||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
glnx_unref_object OstreeMetalink *metalink = NULL;
|
||||
GError *local_error = NULL;
|
||||
SoupURI *uri;
|
||||
const char *base_path;
|
||||
g_autofree char *path = NULL;
|
||||
|
||||
metalink = _ostree_metalink_new (fetcher, "summary.sig",
|
||||
base_path = soup_uri_get_path (base_uri);
|
||||
path = g_build_filename (base_path, filenames[i], NULL);
|
||||
uri = soup_uri_new_with_base (base_uri, path);
|
||||
|
||||
ret = _ostree_fetcher_request_uri_to_membuf (fetcher, uri,
|
||||
FALSE, TRUE,
|
||||
outputs[i],
|
||||
main_loop,
|
||||
OSTREE_MAX_METADATA_SIZE,
|
||||
metalink_uri);
|
||||
cancellable, error);
|
||||
soup_uri_free (uri);
|
||||
|
||||
_ostree_metalink_request_sync (metalink, main_loop,
|
||||
NULL, out_signatures, NULL,
|
||||
cancellable, &local_error);
|
||||
|
||||
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||
{
|
||||
g_clear_error (&local_error);
|
||||
*out_signatures = NULL;
|
||||
}
|
||||
else if (local_error != NULL)
|
||||
{
|
||||
g_propagate_error (error, local_error);
|
||||
if (!ret)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
out:
|
||||
if (metalink_uri != NULL)
|
||||
soup_uri_free (metalink_uri);
|
||||
out:
|
||||
if (base_uri != NULL)
|
||||
soup_uri_free (base_uri);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -1883,25 +1817,14 @@ ostree_repo_remote_fetch_summary (OstreeRepo *self,
|
|||
&metalink_url_string, error))
|
||||
goto out;
|
||||
|
||||
if (metalink_url_string == NULL)
|
||||
{
|
||||
if (!repo_remote_fetch_summary_url (self, name,
|
||||
&summary,
|
||||
&signatures,
|
||||
cancellable,
|
||||
error))
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!repo_remote_fetch_summary_metalink (self, name,
|
||||
if (!repo_remote_fetch_summary (self,
|
||||
name,
|
||||
metalink_url_string,
|
||||
&summary,
|
||||
&signatures,
|
||||
cancellable,
|
||||
error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!ostree_repo_remote_get_gpg_verify_summary (self, name, &gpg_verify_summary, error))
|
||||
goto out;
|
||||
|
|
|
|||
Loading…
Reference in New Issue