forked from Mirrors/flatpak-builder
file/archive source: Add mirror-urls
parent
582c1b5708
commit
9c10e1d086
|
@ -607,6 +607,10 @@
|
|||
<term><option>url</option> (string)</term>
|
||||
<listitem><para>The URL of a remote archive that will be downloaded. This overrides path if both are specified.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>mirror-urls</option> (array of strings)</term>
|
||||
<listitem><para>A list of alternative urls that are used if the main url fails.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>md5</option> (string)</term>
|
||||
<listitem><para>The md5 checksum of the file, verified after download</para>
|
||||
|
@ -741,6 +745,10 @@
|
|||
<term><option>url</option> (string)</term>
|
||||
<listitem><para>The URL of a remote file that will be downloaded and copied into the source dir. This overrides path if both are specified.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>mirror-urls</option> (array of strings)</term>
|
||||
<listitem><para>A list of alternative urls that are used if the main url fails.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>md5</option> (string)</term>
|
||||
<listitem><para>The md5 checksum of the file, verified after download. This is optional for local files.</para>
|
||||
|
|
|
@ -362,6 +362,7 @@ builder_context_set_sources_urls (BuilderContext *self,
|
|||
gboolean
|
||||
builder_context_download_uri (BuilderContext *self,
|
||||
const char *url,
|
||||
const char **mirrors,
|
||||
GFile *dest,
|
||||
const char *checksums[BUILDER_CHECKSUMS_LEN],
|
||||
GChecksumType checksums_type[BUILDER_CHECKSUMS_LEN],
|
||||
|
@ -369,6 +370,7 @@ builder_context_download_uri (BuilderContext *self,
|
|||
{
|
||||
int i;
|
||||
g_autoptr(SoupURI) original_uri = soup_uri_new (url);
|
||||
g_autoptr(GError) first_error = NULL;
|
||||
|
||||
if (original_uri == NULL)
|
||||
return flatpak_fail (error, _("Could not parse URI “%s”"), url);
|
||||
|
@ -404,8 +406,40 @@ builder_context_download_uri (BuilderContext *self,
|
|||
dest,
|
||||
checksums, checksums_type,
|
||||
builder_context_get_curl_session (self),
|
||||
error))
|
||||
return FALSE;
|
||||
&first_error))
|
||||
{
|
||||
gboolean mirror_ok = FALSE;
|
||||
|
||||
if (mirrors != NULL && mirrors[0] != NULL)
|
||||
{
|
||||
g_print ("Error downloading, trying mirrors\n");
|
||||
for (i = 0; mirrors[i] != NULL; i++)
|
||||
{
|
||||
g_autoptr(GError) mirror_error = NULL;
|
||||
g_autoptr(SoupURI) mirror_uri = soup_uri_new (mirrors[i]);
|
||||
g_print ("Trying mirror %s\n", mirrors[i]);
|
||||
if (!builder_download_uri (mirror_uri,
|
||||
dest,
|
||||
checksums, checksums_type,
|
||||
builder_context_get_curl_session (self),
|
||||
&mirror_error))
|
||||
{
|
||||
g_print ("Error downloading mirror: %s\n", mirror_error->message);
|
||||
}
|
||||
else
|
||||
{
|
||||
mirror_ok = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!mirror_ok)
|
||||
{
|
||||
g_propagate_error (error, g_steal_pointer (&first_error));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ void builder_context_set_sources_urls (BuilderContext *self,
|
|||
GPtrArray *sources_urls);
|
||||
gboolean builder_context_download_uri (BuilderContext *self,
|
||||
const char *url,
|
||||
const char **mirrors,
|
||||
GFile *dest,
|
||||
const char *checksums[BUILDER_CHECKSUMS_LEN],
|
||||
GChecksumType checksums_type[BUILDER_CHECKSUMS_LEN],
|
||||
|
|
|
@ -38,6 +38,7 @@ struct BuilderSourceArchive
|
|||
|
||||
char *path;
|
||||
char *url;
|
||||
char **mirror_urls;
|
||||
char *md5;
|
||||
char *sha1;
|
||||
char *sha256;
|
||||
|
@ -63,6 +64,7 @@ enum {
|
|||
PROP_SHA512,
|
||||
PROP_STRIP_COMPONENTS,
|
||||
PROP_DEST_FILENAME,
|
||||
PROP_MIRROR_URLS,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
|
@ -130,6 +132,7 @@ builder_source_archive_finalize (GObject *object)
|
|||
g_free (self->sha256);
|
||||
g_free (self->sha512);
|
||||
g_free (self->dest_filename);
|
||||
g_strfreev (self->mirror_urls);
|
||||
|
||||
G_OBJECT_CLASS (builder_source_archive_parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -176,6 +179,10 @@ builder_source_archive_get_property (GObject *object,
|
|||
g_value_set_string (value, self->dest_filename);
|
||||
break;
|
||||
|
||||
case PROP_MIRROR_URLS:
|
||||
g_value_set_boxed (value, self->mirror_urls);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
|
@ -188,6 +195,7 @@ builder_source_archive_set_property (GObject *object,
|
|||
GParamSpec *pspec)
|
||||
{
|
||||
BuilderSourceArchive *self = BUILDER_SOURCE_ARCHIVE (object);
|
||||
gchar **tmp;
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
|
@ -230,6 +238,12 @@ builder_source_archive_set_property (GObject *object,
|
|||
self->dest_filename = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_MIRROR_URLS:
|
||||
tmp = self->mirror_urls;
|
||||
self->mirror_urls = g_strdupv (g_value_get_boxed (value));
|
||||
g_strfreev (tmp);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
|
@ -398,6 +412,7 @@ builder_source_archive_download (BuilderSource *source,
|
|||
|
||||
if (!builder_context_download_uri (context,
|
||||
self->url,
|
||||
(const char **)self->mirror_urls,
|
||||
file,
|
||||
checksums,
|
||||
checksums_type,
|
||||
|
@ -721,6 +736,7 @@ builder_source_archive_checksum (BuilderSource *source,
|
|||
builder_cache_checksum_compat_str (cache, self->sha512);
|
||||
builder_cache_checksum_uint32 (cache, self->strip_components);
|
||||
builder_cache_checksum_compat_str (cache, self->dest_filename);
|
||||
builder_cache_checksum_compat_strv (cache, self->mirror_urls);
|
||||
}
|
||||
|
||||
|
||||
|
@ -797,6 +813,13 @@ builder_source_archive_class_init (BuilderSourceArchiveClass *klass)
|
|||
"",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_MIRROR_URLS,
|
||||
g_param_spec_boxed ("mirror-urls",
|
||||
"",
|
||||
"",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -38,6 +38,7 @@ struct BuilderSourceFile
|
|||
|
||||
char *path;
|
||||
char *url;
|
||||
char **mirror_urls;
|
||||
char *md5;
|
||||
char *sha1;
|
||||
char *sha256;
|
||||
|
@ -61,6 +62,7 @@ enum {
|
|||
PROP_SHA256,
|
||||
PROP_SHA512,
|
||||
PROP_DEST_FILENAME,
|
||||
PROP_MIRROR_URLS,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
|
@ -76,6 +78,7 @@ builder_source_file_finalize (GObject *object)
|
|||
g_free (self->sha256);
|
||||
g_free (self->sha512);
|
||||
g_free (self->dest_filename);
|
||||
g_strfreev (self->mirror_urls);
|
||||
|
||||
G_OBJECT_CLASS (builder_source_file_parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -118,6 +121,10 @@ builder_source_file_get_property (GObject *object,
|
|||
g_value_set_string (value, self->dest_filename);
|
||||
break;
|
||||
|
||||
case PROP_MIRROR_URLS:
|
||||
g_value_set_boxed (value, self->mirror_urls);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
|
@ -130,6 +137,7 @@ builder_source_file_set_property (GObject *object,
|
|||
GParamSpec *pspec)
|
||||
{
|
||||
BuilderSourceFile *self = BUILDER_SOURCE_FILE (object);
|
||||
gchar **tmp;
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
|
@ -168,6 +176,12 @@ builder_source_file_set_property (GObject *object,
|
|||
self->dest_filename = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_MIRROR_URLS:
|
||||
tmp = self->mirror_urls;
|
||||
self->mirror_urls = g_strdupv (g_value_get_boxed (value));
|
||||
g_strfreev (tmp);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
|
@ -378,6 +392,7 @@ builder_source_file_download (BuilderSource *source,
|
|||
|
||||
if (!builder_context_download_uri (context,
|
||||
self->url,
|
||||
(const char **)self->mirror_urls,
|
||||
file,
|
||||
checksums,
|
||||
checksums_type,
|
||||
|
@ -562,6 +577,7 @@ builder_source_file_checksum (BuilderSource *source,
|
|||
builder_cache_checksum_compat_str (cache, self->sha1);
|
||||
builder_cache_checksum_compat_str (cache, self->sha512);
|
||||
builder_cache_checksum_str (cache, self->dest_filename);
|
||||
builder_cache_checksum_compat_strv (cache, self->mirror_urls);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -630,6 +646,13 @@ builder_source_file_class_init (BuilderSourceFileClass *klass)
|
|||
"",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_MIRROR_URLS,
|
||||
g_param_spec_boxed ("mirror-urls",
|
||||
"",
|
||||
"",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue