Allow installing firmware without a specified device ID

This commit is contained in:
Richard Hughes 2015-03-06 10:09:55 +00:00
parent 18e7591104
commit d079b1a6ca
4 changed files with 78 additions and 12 deletions

View File

@ -26,6 +26,8 @@
#define FWUPD_DBUS_SERVICE "org.freedesktop.fwupd"
#define FWUPD_DBUS_INTERFACE "org.freedesktop.fwupd"
#define FWUPD_DEVICE_ID_ANY "*"
#define FU_ERROR fu_error_quark()
#define FU_DEVICE_KEY_VERSION "Version"

View File

@ -109,6 +109,25 @@ fu_main_get_item_by_id (FuMainPrivate *priv, const gchar *id)
return NULL;
}
/**
* fu_main_get_item_by_guid:
**/
static FuDeviceItem *
fu_main_get_item_by_guid (FuMainPrivate *priv, const gchar *guid)
{
FuDeviceItem *item;
const gchar *tmp;
guint i;
for (i = 0; i < priv->devices->len; i++) {
item = g_ptr_array_index (priv->devices, i);
tmp = fu_device_get_metadata (item->device, FU_DEVICE_KEY_GUID);
if (g_strcmp0 (tmp, guid) == 0)
return item;
}
return NULL;
}
typedef struct {
GDBusMethodInvocation *invocation;
FuDevice *device;
@ -153,7 +172,8 @@ fu_main_helper_free (FuMainAuthHelper *helper)
g_free (helper->id);
g_free (helper->inf_filename);
g_free (helper->tmp_path);
g_object_unref (helper->device);
if (helper->device != NULL)
g_object_unref (helper->device);
g_object_unref (helper->invocation);
g_object_unref (helper->cab_stream);
g_free (helper);
@ -358,6 +378,22 @@ fu_main_update_helper (FuMainAuthHelper *helper, GError **error)
error_local->message);
return FALSE;
}
/* are we matching *any* hardware */
if (helper->device == NULL) {
FuDeviceItem *item;
item = fu_main_get_item_by_guid (helper->priv, guid);
if (item == NULL) {
g_set_error (error,
FU_ERROR,
FU_ERROR_INVALID_FILE,
"no hardware matched %s",
guid);
return FALSE;
}
helper->device = g_object_ref (item->device);
}
tmp = fu_device_get_metadata (helper->device, FU_DEVICE_KEY_GUID);
if (g_strcmp0 (guid, tmp) != 0) {
g_set_error (error,
@ -498,7 +534,7 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
/* return '' */
if (g_strcmp0 (method_name, "Update") == 0) {
FuDeviceItem *item;
FuDeviceItem *item = NULL;
FuMainAuthHelper *helper;
FuProviderFlags flags = FU_PROVIDER_UPDATE_FLAG_NONE;
GDBusMessage *message;
@ -515,14 +551,16 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
/* check the id exists */
g_variant_get (parameters, "(&sha{sv})", &id, &fd_handle, &iter);
g_debug ("Called %s(%s,%i)", method_name, id, fd_handle);
item = fu_main_get_item_by_id (priv, id);
if (item == NULL) {
g_dbus_method_invocation_return_error (invocation,
FU_ERROR,
FU_ERROR_NO_SUCH_DEVICE,
"no such ID %s",
id);
return;
if (g_strcmp0 (id, FWUPD_DEVICE_ID_ANY) != 0) {
item = fu_main_get_item_by_id (priv, id);
if (item == NULL) {
g_dbus_method_invocation_return_error (invocation,
FU_ERROR,
FU_ERROR_NO_SUCH_DEVICE,
"no such device %s",
id);
return;
}
}
/* get options */
@ -565,7 +603,8 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
helper->id = g_strdup (id);
helper->flags = flags;
helper->priv = priv;
helper->device = g_object_ref (item->device);
if (item != NULL)
helper->device = g_object_ref (item->device);
if (!fu_main_update_helper (helper, &error)) {
g_dbus_method_invocation_return_gerror (helper->invocation,
error);

View File

@ -372,6 +372,23 @@ fu_util_update_online (FuUtilPrivate *priv, gchar **values, GError **error)
priv->flags, error);
}
/**
* fu_util_install:
**/
static gboolean
fu_util_install (FuUtilPrivate *priv, gchar **values, GError **error)
{
if (g_strv_length (values) != 1) {
g_set_error_literal (error,
FU_ERROR,
FU_ERROR_INTERNAL,
"Invalid arguments: expected 'filename'");
return FALSE;
}
return fu_util_update (priv, FWUPD_DEVICE_ID_ANY,
values[0], priv->flags, error);
}
/**
* fu_util_update_prepared:
**/
@ -523,6 +540,12 @@ main (int argc, char *argv[])
/* TRANSLATORS: command description */
_("Install prepared updates now"),
fu_util_update_prepared);
fu_util_add (priv->cmd_array,
"install",
NULL,
/* TRANSLATORS: command description */
_("Install a firmware file on this hardware"),
fu_util_install);
/* sort by command name */
g_ptr_array_sort (priv->cmd_array,

View File

@ -52,7 +52,9 @@
<arg type='s' name='id' direction='in'>
<doc:doc>
<doc:summary>
<doc:para>An ID, typically a GUID of the hardware to update.</doc:para>
<doc:para>
An ID, typically a GUID of the hardware to update, or the string
<doc:tt>*</doc:tt> to match any applicable hardware.</doc:para>
</doc:summary>
</doc:doc>
</arg>