Fix the DeviceID set by GetDetails
The returned ID is the result of the SHA1 hash of the actual device ID. This
does not match anything found by the client, and so the install fails.
Richard Hughes
3 years ago
1179 | 1179 | fwupd_device_set_name (FWUPD_DEVICE (self), new->str); |
1180 | 1180 | } |
1181 | 1181 | |
1182 | static gboolean | |
1183 | fu_device_id_is_valid (const gchar *device_id) | |
1184 | { | |
1185 | if (device_id == NULL) | |
1186 | return FALSE; | |
1187 | if (strlen (device_id) != 40) | |
1188 | return FALSE; | |
1189 | for (guint i = 0; device_id[i] != '\0'; i++) { | |
1190 | gchar tmp = device_id[i]; | |
1191 | /* isalnum isn't case specific */ | |
1192 | if ((tmp < 'a' || tmp > 'f') && (tmp < '0' || tmp > '9')) | |
1193 | return FALSE; | |
1194 | } | |
1195 | return TRUE; | |
1196 | } | |
1197 | ||
1182 | 1198 | /** |
1183 | 1199 | * fu_device_set_id: |
1184 | 1200 | * @self: A #FuDevice |
1188 | 1204 | * device, so that any similar device plugged into a different slot will |
1189 | 1205 | * have a different @id string. |
1190 | 1206 | * |
1191 | * The @id will be converted to a SHA1 hash before the device is added to the | |
1192 | * daemon, and plugins should not assume that the ID that is set here is the | |
1193 | * same as what is returned by fu_device_get_id(). | |
1207 | * The @id will be converted to a SHA1 hash if required before the device is | |
1208 | * added to the daemon, and plugins should not assume that the ID that is set | |
1209 | * here is the same as what is returned by fu_device_get_id(). | |
1194 | 1210 | * |
1195 | 1211 | * Since: 0.7.1 |
1196 | 1212 | **/ |
1203 | 1219 | g_return_if_fail (FU_IS_DEVICE (self)); |
1204 | 1220 | g_return_if_fail (id != NULL); |
1205 | 1221 | |
1206 | id_hash = g_compute_checksum_for_string (G_CHECKSUM_SHA1, id, -1); | |
1207 | g_debug ("using %s for %s", id_hash, id); | |
1222 | /* allow sane device-id to be set directly */ | |
1223 | if (fu_device_id_is_valid (id)) { | |
1224 | id_hash = g_strdup (id); | |
1225 | } else { | |
1226 | id_hash = g_compute_checksum_for_string (G_CHECKSUM_SHA1, id, -1); | |
1227 | g_debug ("using %s for %s", id_hash, id); | |
1228 | } | |
1208 | 1229 | fwupd_device_set_id (FWUPD_DEVICE (self), id_hash); |
1209 | 1230 | |
1210 | 1231 | /* ensure the parent ID is set */ |