mirror of
https://git.proxmox.com/git/fwupd
synced 2025-06-06 03:40:12 +00:00
Show a nicer error message if the requirement fails
`Not compatible with fwupd version 1.0.2, requires >= 1.0.3` ...is easier to understand than... `Value of org.freedesktop.fwupd incorrect: failed predicate [1.0.3 ge 1.0.2]`
This commit is contained in:
parent
104f651132
commit
88adcbe601
120
src/fu-engine.c
120
src/fu-engine.c
@ -93,6 +93,11 @@ static guint signals[SIGNAL_LAST] = { 0 };
|
|||||||
|
|
||||||
G_DEFINE_TYPE (FuEngine, fu_engine, G_TYPE_OBJECT)
|
G_DEFINE_TYPE (FuEngine, fu_engine, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
#define FU_ENGINE_REQUIREMENT_FIRMWARE_RUNTIME NULL /* yes, NULL */
|
||||||
|
#define FU_ENGINE_REQUIREMENT_FIRMWARE_BOOTLOADER "bootloader"
|
||||||
|
#define FU_ENGINE_REQUIREMENT_FIRMWARE_VENDOR "vendor-id"
|
||||||
|
#define FU_ENGINE_REQUIREMENT_ID_FWUPD "org.freedesktop.fwupd"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fu_engine_emit_changed (FuEngine *self)
|
fu_engine_emit_changed (FuEngine *self)
|
||||||
{
|
{
|
||||||
@ -754,6 +759,7 @@ fu_engine_check_version_requirement (AsApp *app,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
AsRequire *req;
|
AsRequire *req;
|
||||||
|
g_autoptr(GError) error_local = NULL;
|
||||||
|
|
||||||
/* check args */
|
/* check args */
|
||||||
if (version == NULL) {
|
if (version == NULL) {
|
||||||
@ -771,8 +777,86 @@ fu_engine_check_version_requirement (AsApp *app,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check version */
|
/* check version */
|
||||||
if (!as_require_version_compare (req, version, error)) {
|
if (!as_require_version_compare (req, version, &error_local)) {
|
||||||
g_prefix_error (error, "Value of %s incorrect: ", id);
|
|
||||||
|
/* firmware */
|
||||||
|
if (g_strcmp0 (id, FU_ENGINE_REQUIREMENT_FIRMWARE_RUNTIME) == 0) {
|
||||||
|
if (as_require_get_compare (req) == AS_REQUIRE_COMPARE_GE) {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"Not compatible with firmware version %s, requires >= %s",
|
||||||
|
version, as_require_get_version (req));
|
||||||
|
} else {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"Not compatible with firmware version: %s",
|
||||||
|
error_local->message);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* fwupd */
|
||||||
|
if (g_strcmp0 (id, FU_ENGINE_REQUIREMENT_ID_FWUPD) == 0) {
|
||||||
|
if (as_require_get_compare (req) == AS_REQUIRE_COMPARE_GE) {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"Not compatible with fwupd version %s, requires >= %s",
|
||||||
|
version, as_require_get_version (req));
|
||||||
|
} else {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"Not compatible with fwupd version: %s",
|
||||||
|
error_local->message);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bootloader */
|
||||||
|
if (g_strcmp0 (id, FU_ENGINE_REQUIREMENT_FIRMWARE_BOOTLOADER) == 0) {
|
||||||
|
if (as_require_get_compare (req) == AS_REQUIRE_COMPARE_GE) {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"Not compatible with bootloader version %s, requires >= %s",
|
||||||
|
version, as_require_get_version (req));
|
||||||
|
} else {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"Not compatible with bootloader version: %s",
|
||||||
|
error_local->message);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vendor */
|
||||||
|
if (g_strcmp0 (id, FU_ENGINE_REQUIREMENT_FIRMWARE_VENDOR) == 0) {
|
||||||
|
if (as_require_get_compare (req) == AS_REQUIRE_COMPARE_GE) {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"Not compatible with vendor %s, requires >= %s",
|
||||||
|
version, as_require_get_version (req));
|
||||||
|
} else {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"Not compatible with vendor: %s",
|
||||||
|
error_local->message);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* anything else */
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INVALID_FILE,
|
||||||
|
"Not compatible with %s: %s",
|
||||||
|
id, error_local->message);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -816,10 +900,10 @@ fu_engine_check_requirements (FuEngine *self, AsApp *app, FuDevice *device, GErr
|
|||||||
{
|
{
|
||||||
/* make sure requirements are satisfied */
|
/* make sure requirements are satisfied */
|
||||||
if (!fu_engine_check_version_requirement (app,
|
if (!fu_engine_check_version_requirement (app,
|
||||||
AS_REQUIRE_KIND_ID,
|
AS_REQUIRE_KIND_ID,
|
||||||
"org.freedesktop.fwupd",
|
FU_ENGINE_REQUIREMENT_ID_FWUPD,
|
||||||
VERSION,
|
VERSION,
|
||||||
error)) {
|
error)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#if AS_CHECK_VERSION(0,7,4)
|
#if AS_CHECK_VERSION(0,7,4)
|
||||||
@ -829,24 +913,24 @@ fu_engine_check_requirements (FuEngine *self, AsApp *app, FuDevice *device, GErr
|
|||||||
|
|
||||||
if (device != NULL) {
|
if (device != NULL) {
|
||||||
if (!fu_engine_check_version_requirement (app,
|
if (!fu_engine_check_version_requirement (app,
|
||||||
AS_REQUIRE_KIND_FIRMWARE,
|
AS_REQUIRE_KIND_FIRMWARE,
|
||||||
NULL,
|
FU_ENGINE_REQUIREMENT_FIRMWARE_RUNTIME,
|
||||||
fu_device_get_version (device),
|
fu_device_get_version (device),
|
||||||
error)) {
|
error)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!fu_engine_check_version_requirement (app,
|
if (!fu_engine_check_version_requirement (app,
|
||||||
AS_REQUIRE_KIND_FIRMWARE,
|
AS_REQUIRE_KIND_FIRMWARE,
|
||||||
"bootloader",
|
FU_ENGINE_REQUIREMENT_FIRMWARE_BOOTLOADER,
|
||||||
fu_device_get_version_bootloader (device),
|
fu_device_get_version_bootloader (device),
|
||||||
error)) {
|
error)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!fu_engine_check_version_requirement (app,
|
if (!fu_engine_check_version_requirement (app,
|
||||||
AS_REQUIRE_KIND_FIRMWARE,
|
AS_REQUIRE_KIND_FIRMWARE,
|
||||||
"vendor-id",
|
FU_ENGINE_REQUIREMENT_FIRMWARE_VENDOR,
|
||||||
fu_device_get_vendor_id (device),
|
fu_device_get_vendor_id (device),
|
||||||
error)) {
|
error)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user