[gnome-software: 70/72] gs-utils: Create cache directory even if running under unit tests
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 70/72] gs-utils: Create cache directory even if running under unit tests
- Date: Wed, 15 Dec 2021 13:00:56 +0000 (UTC)
commit e0b885a48bf3dd494280209a8a7e29eafa4a7be1
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Dec 8 10:48:51 2021 +0000
gs-utils: Create cache directory even if running under unit tests
Previously the `GS_UTILS_CACHE_FLAG_CREATE_DIRECTORY` flag was ignored
if `GS_SELF_TEST_CACHEDIR` was set, even if the cache subdirectory of
the cachedir didn’t exist.
Create the directory if it doesn’t exist, just as if
`GS_SELF_TEST_CACHEDIR` wasn’t set.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
lib/gs-utils.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index 19d21ec78..84e33f769 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -157,11 +157,23 @@ gs_utils_get_cache_filename (const gchar *kind,
g_autofree gchar *cachedir = NULL;
g_autoptr(GFile) cachedir_file = NULL;
g_autoptr(GPtrArray) candidates = g_ptr_array_new_with_free_func (g_free);
+ g_autoptr(GError) local_error = NULL;
/* in the self tests */
tmp = g_getenv ("GS_SELF_TEST_CACHEDIR");
- if (tmp != NULL)
- return g_build_filename (tmp, kind, resource, NULL);
+ if (tmp != NULL) {
+ cachedir = g_build_filename (tmp, kind, NULL);
+ cachedir_file = g_file_new_for_path (cachedir);
+
+ if ((flags & GS_UTILS_CACHE_FLAG_CREATE_DIRECTORY) &&
+ !g_file_make_directory_with_parents (cachedir_file, NULL, &local_error) &&
+ !g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
+ g_propagate_error (error, g_steal_pointer (&local_error));
+ return NULL;
+ }
+
+ return g_build_filename (cachedir, resource, NULL);;
+ }
/* get basename */
if (flags & GS_UTILS_CACHE_FLAG_USE_HASH) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]