diff --git a/libfwupdplugin/fu-self-test.c b/libfwupdplugin/fu-self-test.c index faf597330..e3f06e446 100644 --- a/libfwupdplugin/fu-self-test.c +++ b/libfwupdplugin/fu-self-test.c @@ -596,7 +596,7 @@ fu_plugin_quirks_func (void) g_autoptr(FuContext) ctx = fu_context_new (); g_autoptr(GError) error = NULL; - ret = fu_context_load_quirks (ctx, FU_QUIRKS_LOAD_FLAG_NONE, &error); + ret = fu_context_load_quirks (ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); @@ -626,7 +626,7 @@ fu_plugin_quirks_performance_func (void) g_autoptr(GError) error = NULL; const gchar *keys[] = { "Name", "Children", "Flags", NULL }; - ret = fu_quirks_load (quirks, FU_QUIRKS_LOAD_FLAG_NONE, &error); + ret = fu_quirks_load (quirks, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); @@ -652,7 +652,7 @@ fu_plugin_quirks_device_func (void) g_autoptr(FuContext) ctx = fu_context_new (); g_autoptr(GError) error = NULL; - ret = fu_context_load_quirks (ctx, FU_QUIRKS_LOAD_FLAG_NONE, &error); + ret = fu_context_load_quirks (ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); @@ -1384,6 +1384,11 @@ fu_device_instance_ids_func (void) g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); g_autoptr(GError) error = NULL; + /* do not save silo */ + ret = fu_context_load_quirks (ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error); + g_assert_no_error (error); + g_assert_true (ret); + /* sanity check */ g_assert_false (fu_device_has_guid (device, "c0a26214-223b-572a-9477-cde897fe8619")); @@ -1542,6 +1547,11 @@ fu_device_children_func (void) g_autoptr(FuDevice) parent = fu_device_new_with_context (ctx); g_autoptr(GError) error = NULL; + /* do not save silo */ + ret = fu_context_load_quirks (ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error); + g_assert_no_error (error); + g_assert_true (ret); + fu_device_set_physical_id (child, "dummy"); fu_device_set_physical_id (parent, "dummy"); diff --git a/plugins/dell/fu-self-test.c b/plugins/dell/fu-self-test.c index c3c050776..13f1b0036 100644 --- a/plugins/dell/fu-self-test.c +++ b/plugins/dell/fu-self-test.c @@ -494,6 +494,11 @@ fu_test_self_init (FuTest *self) g_autofree gchar *pluginfn_uefi = NULL; g_autofree gchar *pluginfn_dell = NULL; + /* do not save silo */ + ret = fu_context_load_quirks (ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error); + g_assert_no_error (error); + g_assert_true (ret); + self->plugin_uefi_capsule = fu_plugin_new (ctx); pluginfn_uefi = g_build_filename (PLUGINBUILDDIR, "..", "uefi-capsule", "libfu_plugin_uefi_capsule." G_MODULE_SUFFIX, diff --git a/plugins/uefi-capsule/fu-self-test.c b/plugins/uefi-capsule/fu-self-test.c index db9e2b539..662baa460 100644 --- a/plugins/uefi-capsule/fu-self-test.c +++ b/plugins/uefi-capsule/fu-self-test.c @@ -168,6 +168,11 @@ fu_uefi_plugin_func (void) return; #endif + /* do not save silo */ + ret = fu_context_load_quirks (ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error); + g_assert_no_error (error); + g_assert_true (ret); + /* add each device */ ret = fu_backend_coldplug (backend, &error); g_assert_no_error (error); diff --git a/src/fu-engine.c b/src/fu-engine.c index 0a0b0e4ef..965859bc5 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -3569,8 +3569,6 @@ fu_engine_load_metadata_store (FuEngine *self, FuEngineLoadFlags flags, GError * { GPtrArray *remotes; XbBuilderCompileFlags compile_flags = XB_BUILDER_COMPILE_FLAG_IGNORE_INVALID; - g_autofree gchar *cachedirpkg = NULL; - g_autofree gchar *xmlbfn = NULL; g_autoptr(GFile) xmlb = NULL; g_autoptr(GPtrArray) components = NULL; g_autoptr(XbBuilder) builder = xb_builder_new (); @@ -3653,12 +3651,19 @@ fu_engine_load_metadata_store (FuEngine *self, FuEngineLoadFlags flags, GError * compile_flags |= XB_BUILDER_COMPILE_FLAG_IGNORE_GUID; /* ensure silo is up to date */ - cachedirpkg = fu_common_get_path (FU_PATH_KIND_CACHEDIR_PKG); - xmlbfn = g_build_filename (cachedirpkg, "metadata.xmlb", NULL); - xmlb = g_file_new_for_path (xmlbfn); + if (flags & FU_ENGINE_LOAD_FLAG_NO_CACHE) { + g_autoptr(GFileIOStream) iostr = NULL; + xmlb = g_file_new_tmp (NULL, &iostr, error); + if (xmlb == NULL) + return FALSE; + } else { + g_autofree gchar *cachedirpkg = fu_common_get_path (FU_PATH_KIND_CACHEDIR_PKG); + g_autofree gchar *xmlbfn = g_build_filename (cachedirpkg, "metadata.xmlb", NULL); + xmlb = g_file_new_for_path (xmlbfn); + } self->silo = xb_builder_ensure (builder, xmlb, compile_flags, NULL, error); if (self->silo == NULL) { - g_prefix_error (error, "cannot create file %s: ", xmlbfn); + g_prefix_error (error, "cannot create metadata.xmlb: "); return FALSE; } @@ -6556,6 +6561,8 @@ fu_engine_load (FuEngine *self, FuEngineLoadFlags flags, GError **error) FuRemoteListLoadFlags remote_list_flags = FU_REMOTE_LIST_LOAD_FLAG_NONE; if (flags & FU_ENGINE_LOAD_FLAG_READONLY) remote_list_flags |= FU_REMOTE_LIST_LOAD_FLAG_READONLY_FS; + if (flags & FU_ENGINE_LOAD_FLAG_NO_CACHE) + remote_list_flags |= FU_REMOTE_LIST_LOAD_FLAG_NO_CACHE; if (!fu_remote_list_load (self->remote_list, remote_list_flags, error)) { g_prefix_error (error, "Failed to load remotes: "); return FALSE; @@ -6657,6 +6664,8 @@ fu_engine_load (FuEngine *self, FuEngineLoadFlags flags, GError **error) /* on a read-only filesystem don't care about the cache GUID */ if (flags & FU_ENGINE_LOAD_FLAG_READONLY) quirks_flags |= FU_QUIRKS_LOAD_FLAG_READONLY_FS; + if (flags & FU_ENGINE_LOAD_FLAG_NO_CACHE) + quirks_flags |= FU_QUIRKS_LOAD_FLAG_NO_CACHE; fu_engine_load_quirks (self, quirks_flags); /* set up battery threshold */ diff --git a/src/fu-engine.h b/src/fu-engine.h index 784fb7934..47cde4d2a 100644 --- a/src/fu-engine.h +++ b/src/fu-engine.h @@ -30,6 +30,7 @@ G_DECLARE_FINAL_TYPE (FuEngine, fu_engine, FU, ENGINE, GObject) * @FU_ENGINE_LOAD_FLAG_COLDPLUG: Enumerate devices * @FU_ENGINE_LOAD_FLAG_REMOTES: Enumerate remotes * @FU_ENGINE_LOAD_FLAG_HWINFO: Load details about the hardware + * @FU_ENGINE_LOAD_FLAG_NO_CACHE: Do not save persistent xmlb silos * * The flags to use when loading the engine. **/ @@ -39,6 +40,7 @@ typedef enum { FU_ENGINE_LOAD_FLAG_COLDPLUG = 1 << 1, FU_ENGINE_LOAD_FLAG_REMOTES = 1 << 2, FU_ENGINE_LOAD_FLAG_HWINFO = 1 << 3, + FU_ENGINE_LOAD_FLAG_NO_CACHE = 1 << 4, /*< private >*/ FU_ENGINE_LOAD_FLAG_LAST } FuEngineLoadFlags; diff --git a/src/fu-remote-list.c b/src/fu-remote-list.c index 4817ee708..b644a98e4 100644 --- a/src/fu-remote-list.c +++ b/src/fu-remote-list.c @@ -419,8 +419,6 @@ gboolean fu_remote_list_load (FuRemoteList *self, FuRemoteListLoadFlags flags, GError **error) { const gchar *const *locales = g_get_language_names (); - g_autofree gchar *cachedirpkg = NULL; - g_autofree gchar *xmlbfn = NULL; g_autoptr(GFile) xmlb = NULL; g_autoptr(XbBuilder) builder = xb_builder_new (); XbBuilderCompileFlags compile_flags = XB_BUILDER_COMPILE_FLAG_SINGLE_LANG | @@ -442,9 +440,16 @@ fu_remote_list_load (FuRemoteList *self, FuRemoteListLoadFlags flags, GError **e compile_flags |= XB_BUILDER_COMPILE_FLAG_IGNORE_GUID; /* build the metainfo silo */ - cachedirpkg = fu_common_get_path (FU_PATH_KIND_CACHEDIR_PKG); - xmlbfn = g_build_filename (cachedirpkg, "metainfo.xmlb", NULL); - xmlb = g_file_new_for_path (xmlbfn); + if (flags & FU_REMOTE_LIST_LOAD_FLAG_NO_CACHE) { + g_autoptr(GFileIOStream) iostr = NULL; + xmlb = g_file_new_tmp (NULL, &iostr, error); + if (xmlb == NULL) + return FALSE; + } else { + g_autofree gchar *cachedirpkg = fu_common_get_path (FU_PATH_KIND_CACHEDIR_PKG); + g_autofree gchar *xmlbfn = g_build_filename (cachedirpkg, "metainfo.xmlb", NULL); + xmlb = g_file_new_for_path (xmlbfn); + } self->silo = xb_builder_ensure (builder, xmlb, compile_flags, NULL, error); if (self->silo == NULL) return FALSE; diff --git a/src/fu-remote-list.h b/src/fu-remote-list.h index daed826a0..d66915eef 100644 --- a/src/fu-remote-list.h +++ b/src/fu-remote-list.h @@ -17,12 +17,14 @@ G_DECLARE_FINAL_TYPE (FuRemoteList, fu_remote_list, FU, REMOTE_LIST, GObject) * FuRemoteListLoadFlags: * @FU_REMOTE_LIST_LOAD_FLAG_NONE: No flags set * @FU_REMOTE_LIST_LOAD_FLAG_READONLY_FS: Ignore readonly filesystem errors + * @FU_REMOTE_LIST_LOAD_FLAG_NO_CACHE: Do not save persistent xmlb silos * * The flags to use when loading a remote_listuration file. **/ typedef enum { FU_REMOTE_LIST_LOAD_FLAG_NONE = 0, FU_REMOTE_LIST_LOAD_FLAG_READONLY_FS = 1 << 0, + FU_REMOTE_LIST_LOAD_FLAG_NO_CACHE = 1 << 1, /*< private >*/ FU_REMOTE_LIST_LOAD_FLAG_LAST } FuRemoteListLoadFlags; diff --git a/src/fu-self-test.c b/src/fu-self-test.c index 9a7d66369..c0bd0d7f9 100644 --- a/src/fu-self-test.c +++ b/src/fu-self-test.c @@ -30,6 +30,7 @@ typedef struct { FuPlugin *plugin; + FuContext *ctx; } FuTest; static GMainLoop *_test_loop = NULL; @@ -100,7 +101,10 @@ fu_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error) static void fu_test_free (FuTest *self) { - g_object_unref (self->plugin); + if (self->ctx != NULL) + g_object_unref (self->ctx); + if (self->plugin != NULL) + g_object_unref (self->plugin); g_free (self); } @@ -112,11 +116,11 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(FuTest, fu_test_free) static void fu_engine_generate_md_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; const gchar *tmp; gboolean ret; g_autofree gchar *filename = NULL; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(GBytes) data = NULL; g_autoptr(GError) error = NULL; @@ -133,7 +137,10 @@ fu_engine_generate_md_func (gconstpointer user_data) g_assert (ret); /* load engine and check the device was found */ - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_REMOTES, &error); + ret = fu_engine_load (engine, + FU_ENGINE_LOAD_FLAG_REMOTES | + FU_ENGINE_LOAD_FLAG_NO_CACHE, + &error); g_assert_no_error (error); g_assert (ret); fu_device_add_guid (device, "12345678-1234-1234-1234-123456789012"); @@ -162,7 +169,7 @@ fu_plugin_hash_func (gconstpointer user_data) g_autoptr(FuPlugin) plugin = fu_plugin_new (NULL); gboolean ret = FALSE; - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NONE, &error); + ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); @@ -368,9 +375,9 @@ fu_engine_requirements_client_pass_func (gconstpointer user_data) static void fu_engine_requirements_version_require_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(FuInstallTask) task = NULL; @@ -455,9 +462,9 @@ fu_engine_requirements_unsupported_func (gconstpointer user_data) static void fu_engine_requirements_child_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuDevice) child = fu_device_new (); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); @@ -512,9 +519,9 @@ fu_engine_requirements_child_func (gconstpointer user_data) static void fu_engine_requirements_child_fail_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuDevice) child = fu_device_new (); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); @@ -609,9 +616,9 @@ fu_engine_requirements_func (gconstpointer user_data) static void fu_engine_requirements_device_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(FuInstallTask) task = NULL; @@ -668,9 +675,9 @@ fu_engine_requirements_device_func (gconstpointer user_data) static void fu_engine_requirements_device_plain_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(FuInstallTask) task = NULL; @@ -716,9 +723,9 @@ fu_engine_requirements_device_plain_func (gconstpointer user_data) static void fu_engine_requirements_version_format_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(FuInstallTask) task = NULL; @@ -768,12 +775,12 @@ fu_engine_requirements_version_format_func (gconstpointer user_data) static void fu_engine_requirements_sibling_device_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) unrelated_device3 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) parent = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) unrelated_device3 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) parent = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(FuInstallTask) task = NULL; @@ -873,10 +880,10 @@ fu_engine_requirements_sibling_device_func (gconstpointer user_data) static void fu_engine_requirements_other_device_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(FuInstallTask) task = NULL; @@ -939,9 +946,9 @@ fu_engine_requirements_other_device_func (gconstpointer user_data) static void fu_engine_requirements_protocol_check_func (gconstpointer user_data) { - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); + FuTest *self = (FuTest *) user_data; + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(GPtrArray) devices = NULL; @@ -1028,10 +1035,10 @@ fu_engine_requirements_protocol_check_func (gconstpointer user_data) static void fu_engine_requirements_parent_device_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(FuInstallTask) task = NULL; @@ -1097,10 +1104,10 @@ fu_engine_requirements_parent_device_func (gconstpointer user_data) static void fu_engine_device_parent_guid_func (gconstpointer user_data) { - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device3 = fu_device_new_with_context (ctx); + FuTest *self = (FuTest *) user_data; + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device3 = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(XbSilo) silo_empty = xb_silo_new (); @@ -1151,11 +1158,11 @@ fu_engine_device_parent_guid_func (gconstpointer user_data) static void fu_engine_device_parent_id_func (gconstpointer user_data) { - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device3 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device4 = fu_device_new_with_context (ctx); + FuTest *self = (FuTest *) user_data; + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device3 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device4 = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(XbSilo) silo_empty = xb_silo_new (); @@ -1221,10 +1228,10 @@ fu_engine_device_parent_id_func (gconstpointer user_data) static void fu_engine_partial_hash_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuPlugin) plugin = fu_plugin_new (NULL); g_autoptr(GError) error = NULL; @@ -1290,10 +1297,10 @@ fu_engine_partial_hash_func (gconstpointer user_data) static void fu_engine_device_unlock_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; g_autofree gchar *filename = NULL; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(GError) error = NULL; g_autoptr(GFile) file = NULL; @@ -1302,7 +1309,7 @@ fu_engine_device_unlock_func (gconstpointer user_data) g_autoptr(XbSilo) silo = NULL; /* load engine to get FuConfig set up */ - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NONE, &error); + ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); @@ -1336,10 +1343,10 @@ fu_engine_device_unlock_func (gconstpointer user_data) static void fu_engine_require_hwid_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; g_autofree gchar *filename = NULL; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(FuInstallTask) task = NULL; @@ -1359,7 +1366,7 @@ fu_engine_require_hwid_func (gconstpointer user_data) fu_engine_set_silo (engine, silo_empty); /* load engine to get FuConfig set up */ - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NONE, &error); + ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); @@ -1402,10 +1409,10 @@ fu_engine_require_hwid_func (gconstpointer user_data) static void fu_engine_downgrade_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; FwupdRelease *rel; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(GError) error = NULL; @@ -1490,7 +1497,10 @@ fu_engine_downgrade_func (gconstpointer user_data) g_assert (ret); g_setenv ("CONFIGURATION_DIRECTORY", TESTDATADIR_SRC, TRUE); - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_REMOTES, &error); + ret = fu_engine_load (engine, + FU_ENGINE_LOAD_FLAG_REMOTES | + FU_ENGINE_LOAD_FLAG_NO_CACHE, + &error); g_assert_no_error (error); g_assert (ret); g_assert_cmpint (fu_engine_get_status (engine), ==, FWUPD_STATUS_IDLE); @@ -1582,10 +1592,10 @@ fu_engine_downgrade_func (gconstpointer user_data) static void fu_engine_install_duration_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; FwupdRelease *rel; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuEngineRequest) request = fu_engine_request_new (); g_autoptr(GError) error = NULL; @@ -1620,7 +1630,10 @@ fu_engine_install_duration_func (gconstpointer user_data) g_assert (ret); g_setenv ("CONFIGURATION_DIRECTORY", TESTDATADIR_SRC, TRUE); - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_REMOTES, &error); + ret = fu_engine_load (engine, + FU_ENGINE_LOAD_FLAG_REMOTES | + FU_ENGINE_LOAD_FLAG_NO_CACHE, + &error); g_assert_no_error (error); g_assert (ret); @@ -1665,9 +1678,8 @@ fu_engine_history_func (gconstpointer user_data) g_autofree gchar *device_str_expected = NULL; g_autofree gchar *device_str = NULL; g_autofree gchar *filename = NULL; - g_autoptr(FuContext) ctx = fu_context_new (); g_autoptr(FuDevice) device2 = NULL; - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuHistory) history = NULL; g_autoptr(FuInstallTask) task = NULL; @@ -1690,7 +1702,7 @@ fu_engine_history_func (gconstpointer user_data) fu_engine_add_plugin (engine, self->plugin); g_setenv ("CONFIGURATION_DIRECTORY", TESTDATADIR_SRC, TRUE); - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NONE, &error); + ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); g_assert_cmpint (fu_engine_get_status (engine), ==, FWUPD_STATUS_IDLE); @@ -1800,8 +1812,7 @@ fu_engine_multiple_rels_func (gconstpointer user_data) FuTest *self = (FuTest *) user_data; gboolean ret; g_autofree gchar *filename = NULL; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuInstallTask) task = NULL; g_autoptr(GBytes) blob_cab = NULL; @@ -1820,7 +1831,7 @@ fu_engine_multiple_rels_func (gconstpointer user_data) fu_engine_add_plugin (engine, self->plugin); g_setenv ("CONFIGURATION_DIRECTORY", TESTDATADIR_SRC, TRUE); - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NONE, &error); + ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); g_assert_cmpint (fu_engine_get_status (engine), ==, FWUPD_STATUS_IDLE); @@ -1876,8 +1887,7 @@ fu_engine_history_inherit (gconstpointer user_data) FuTest *self = (FuTest *) user_data; gboolean ret; g_autofree gchar *filename = NULL; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuInstallTask) task = NULL; g_autoptr(GBytes) blob_cab = NULL; @@ -1894,7 +1904,7 @@ fu_engine_history_inherit (gconstpointer user_data) g_setenv ("FWUPD_PLUGIN_TEST", "fail", TRUE); fu_engine_add_plugin (engine, self->plugin); g_setenv ("CONFIGURATION_DIRECTORY", TESTDATADIR_SRC, TRUE); - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NONE, &error); + ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); g_assert_cmpint (fu_engine_get_status (engine), ==, FWUPD_STATUS_IDLE); @@ -1967,7 +1977,7 @@ fu_engine_history_inherit (gconstpointer user_data) engine = fu_engine_new (FU_APP_FLAGS_NONE); fu_engine_set_silo (engine, silo_empty); fu_engine_add_plugin (engine, self->plugin); - device = fu_device_new_with_context (ctx); + device = fu_device_new_with_context (self->ctx); fu_device_add_internal_flag (device, FU_DEVICE_INTERNAL_FLAG_INHERIT_ACTIVATION); fu_device_set_id (device, "test_device"); fu_device_add_vendor_id (device, "USB:FFFF"); @@ -1985,7 +1995,7 @@ fu_engine_history_inherit (gconstpointer user_data) engine = fu_engine_new (FU_APP_FLAGS_NONE); fu_engine_set_silo (engine, silo_empty); fu_engine_add_plugin (engine, self->plugin); - device = fu_device_new_with_context (ctx); + device = fu_device_new_with_context (self->ctx); fu_device_set_id (device, "test_device"); fu_device_add_vendor_id (device, "USB:FFFF"); fu_device_add_protocol (device, "com.acme"); @@ -2007,9 +2017,8 @@ fu_engine_history_error_func (gconstpointer user_data) g_autofree gchar *device_str_expected = NULL; g_autofree gchar *device_str = NULL; g_autofree gchar *filename = NULL; - g_autoptr(FuContext) ctx = fu_context_new (); g_autoptr(FuDevice) device2 = NULL; - g_autoptr(FuDevice) device = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device = fu_device_new_with_context (self->ctx); g_autoptr(FuEngine) engine = fu_engine_new (FU_APP_FLAGS_NONE); g_autoptr(FuHistory) history = NULL; g_autoptr(FuInstallTask) task = NULL; @@ -2029,7 +2038,7 @@ fu_engine_history_error_func (gconstpointer user_data) fu_engine_add_plugin (engine, self->plugin); g_setenv ("CONFIGURATION_DIRECTORY", TESTDATADIR_SRC, TRUE); - ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NONE, &error); + ret = fu_engine_load (engine, FU_ENGINE_LOAD_FLAG_NO_CACHE, &error); g_assert_no_error (error); g_assert (ret); g_assert_cmpint (fu_engine_get_status (engine), ==, FWUPD_STATUS_IDLE); @@ -2151,9 +2160,9 @@ fu_device_list_no_auto_remove_children_func (gconstpointer user_data) static void fu_device_list_delay_func (gconstpointer user_data) { - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); + FuTest *self = (FuTest *) user_data; + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); g_autoptr(FuDeviceList) device_list = fu_device_list_new (); guint added_cnt = 0; guint changed_cnt = 0; @@ -2294,10 +2303,10 @@ fu_device_list_replug_auto_func (gconstpointer user_data) static void fu_device_list_replug_user_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; gboolean ret; - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); g_autoptr(FuDeviceList) device_list = fu_device_list_new (); g_autoptr(GError) error = NULL; FuDeviceListReplugHelper helper; @@ -2369,9 +2378,9 @@ fu_device_list_replug_user_func (gconstpointer user_data) static void fu_device_list_compatible_func (gconstpointer user_data) { - g_autoptr(FuContext) ctx = fu_context_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); + FuTest *self = (FuTest *) user_data; + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); g_autoptr(FuDevice) device_old = NULL; g_autoptr(FuDeviceList) device_list = fu_device_list_new (); g_autoptr(GPtrArray) devices_all = NULL; @@ -2451,10 +2460,10 @@ fu_device_list_compatible_func (gconstpointer user_data) static void fu_device_list_remove_chain_func (gconstpointer user_data) { - g_autoptr(FuContext) ctx = fu_context_new (); + FuTest *self = (FuTest *) user_data; g_autoptr(FuDeviceList) device_list = fu_device_list_new (); - g_autoptr(FuDevice) device_child = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device_parent = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device_child = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device_parent = fu_device_new_with_context (self->ctx); guint added_cnt = 0; guint changed_cnt = 0; @@ -2499,10 +2508,10 @@ fu_device_list_remove_chain_func (gconstpointer user_data) static void fu_device_list_func (gconstpointer user_data) { - g_autoptr(FuContext) ctx = fu_context_new (); + FuTest *self = (FuTest *) user_data; g_autoptr(FuDeviceList) device_list = fu_device_list_new (); - g_autoptr(FuDevice) device1 = fu_device_new_with_context (ctx); - g_autoptr(FuDevice) device2 = fu_device_new_with_context (ctx); + g_autoptr(FuDevice) device1 = fu_device_new_with_context (self->ctx); + g_autoptr(FuDevice) device2 = fu_device_new_with_context (self->ctx); g_autoptr(GPtrArray) devices = NULL; g_autoptr(GPtrArray) devices2 = NULL; g_autoptr(GError) error = NULL; @@ -2851,12 +2860,12 @@ fu_plugin_module_func (gconstpointer user_data) static void fu_history_func (gconstpointer user_data) { + FuTest *self = (FuTest *) user_data; GError *error = NULL; GPtrArray *checksums; gboolean ret; FuDevice *device; FwupdRelease *release; - g_autoptr(FuContext) ctx = fu_context_new (); g_autoptr(FuDevice) device_found = NULL; g_autoptr(FuHistory) history = NULL; g_autoptr(GPtrArray) approved_firmware = NULL; @@ -2875,7 +2884,7 @@ fu_history_func (gconstpointer user_data) g_unlink (filename); /* add a device */ - device = fu_device_new_with_context (ctx); + device = fu_device_new_with_context (self->ctx); fu_device_set_id (device, "self-test"); fu_device_set_name (device, "ColorHug"), fu_device_set_version_format (device, FWUPD_VERSION_FORMAT_TRIPLET); @@ -3348,7 +3357,6 @@ main (int argc, char **argv) gboolean ret; g_autofree gchar *pluginfn = NULL; g_autoptr(GError) error = NULL; - g_autoptr(FuContext) ctx = fu_context_new (); g_autoptr(FuTest) self = g_new0 (FuTest, 1); g_test_init (&argc, &argv, NULL); @@ -3367,8 +3375,14 @@ main (int argc, char **argv) /* ensure empty tree */ fu_self_test_mkroot (); + /* do not save silo */ + self->ctx = fu_context_new (); + ret = fu_context_load_quirks (self->ctx, FU_QUIRKS_LOAD_FLAG_NO_CACHE, &error); + g_assert_no_error (error); + g_assert_true (ret); + /* load the test plugin */ - self->plugin = fu_plugin_new (ctx); + self->plugin = fu_plugin_new (self->ctx); pluginfn = g_build_filename (PLUGINBUILDDIR, "libfu_plugin_test." G_MODULE_SUFFIX, NULL);