diff options
author | Richard Hughes <richard@hughsie.com> | 2015-06-24 09:23:56 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-06-24 09:23:56 +0100 |
commit | b3763a9348ff169c3cd4c3fd48394fe4be29de29 (patch) | |
tree | c0c17ec1ebeb409dede12a8ad2a569cbd2e4b54d | |
parent | a124ab6b737c4510b1fddce0acc9c486a5149146 (diff) | |
download | appstream-glib-b3763a9348ff169c3cd4c3fd48394fe4be29de29.tar.gz |
Add a 'mirror-local-firmware' command to appstream-util
This allows us to mirror vendor-submitted firmware using the file hash.
-rw-r--r-- | client/as-util.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/client/as-util.c b/client/as-util.c index 86e14db..ab92b84 100644 --- a/client/as-util.c +++ b/client/as-util.c @@ -3323,6 +3323,70 @@ as_util_mirror_screenshots (AsUtilPrivate *priv, gchar **values, GError **error) } /** + * as_util_mirror_local_firmware: + **/ +static gboolean +as_util_mirror_local_firmware (AsUtilPrivate *priv, gchar **values, GError **error) +{ + AsApp *app; + GPtrArray *apps; + guint i; + guint j; + _cleanup_object_unref_ AsStore *store = NULL; + _cleanup_object_unref_ GFile *file = NULL; + + /* check args */ + if (g_strv_length (values) != 2) { + g_set_error_literal (error, + AS_ERROR, + AS_ERROR_INVALID_ARGUMENTS, + "Not enough arguments, expected: " + "file url"); + return FALSE; + } + + /* open file */ + store = as_store_new (); + file = g_file_new_for_path (values[0]); + if (!as_store_from_file (store, file, NULL, NULL, error)) + return FALSE; + + /* convert all the screenshots */ + apps = as_store_get_apps (store); + for (i = 0; i < apps->len; i++) { + GPtrArray *releases; + AsRelease *rel; + + /* get app */ + app = g_ptr_array_index (apps, i); + if (as_app_get_id_kind (app) != AS_ID_KIND_FIRMWARE) + continue; + releases = as_app_get_releases (app); + if (releases->len == 0) + continue; + for (j = 0; j < releases->len; j++) { + _cleanup_free_ gchar *loc = NULL; + _cleanup_free_ gchar *fn = NULL; + rel = g_ptr_array_index (releases, j); + fn = g_strdup_printf ("%s.cab", as_release_get_checksum (rel, G_CHECKSUM_SHA1)); + loc = g_build_filename (values[1], fn, NULL); + g_ptr_array_set_size (as_release_get_locations (rel), 0); + as_release_add_location (rel, loc, -1); + } + } + + /* save file */ + if (!as_store_to_file (store, file, + AS_NODE_TO_XML_FLAG_ADD_HEADER | + AS_NODE_TO_XML_FLAG_FORMAT_INDENT | + AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE, + NULL, error)) + return FALSE; + + return TRUE; +} + +/** * as_util_replace_screenshots: * **/ @@ -3813,6 +3877,12 @@ main (int argc, char *argv[]) _("Mirror upstream screenshots"), as_util_mirror_screenshots); as_util_add (priv->cmd_array, + "mirror-local-firmware", + NULL, + /* TRANSLATORS: command description */ + _("Mirror local firmware files"), + as_util_mirror_local_firmware); + as_util_add (priv->cmd_array, "incorporate", NULL, /* TRANSLATORS: command description */ |