From 68bcb8f048317eabd8bac0efc0b68f97d0e90421 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 27 Nov 2018 00:13:22 -0500 Subject: [PATCH 1/2] gresource: Complete the overlay support Unlike the other g_resources_ functions, g_resources_get_info was not respecting G_RESOURCE_OVERLAYS. Add this missing support. Closes: #1445 --- gio/gresource.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gio/gresource.c b/gio/gresource.c index 2844f4808..e71db43ed 100644 --- a/gio/gresource.c +++ b/gio/gresource.c @@ -285,6 +285,27 @@ enumerate_overlay_dir (const gchar *candidate, return FALSE; } +typedef struct { + gsize size; + guint32 flags; +} InfoData; + +static gboolean +get_overlay_info (const gchar *candidate, + gpointer user_data) +{ + InfoData *info = user_data; + GStatBuf buf; + + if (g_stat (candidate, &buf) < 0) + return FALSE; + + info->size = buf.st_size; + info->flags = G_RESOURCE_FLAGS_NONE; + + return TRUE; +} + static gboolean g_resource_find_overlay (const gchar *path, CheckCandidate check, @@ -1251,6 +1272,17 @@ g_resources_get_info (const gchar *path, gboolean res = FALSE; GList *l; gboolean r_res; + InfoData info; + + if (g_resource_find_overlay (path, get_overlay_info, &info)) + { + if (size) + *size = info.size; + if (flags) + *flags = info.flags; + + return TRUE; + } register_lazy_static_resources (); From 37eb1e66456196d4d42592caf72ae72872d577c7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 9 Jan 2019 18:11:45 -0500 Subject: [PATCH 2/2] Add a test for resource overlays Add a test that checks that g_resources_get_info() respects the G_RESOURCE_OVERLAYS environment variable. --- gio/tests/resources.c | 33 ++++++++++++++++++++++++++++++++- gio/tests/test1.overlay | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gio/tests/test1.overlay diff --git a/gio/tests/resources.c b/gio/tests/resources.c index 719624514..6e9c7c5e6 100644 --- a/gio/tests/resources.c +++ b/gio/tests/resources.c @@ -679,7 +679,6 @@ test_uri_query_info (void) g_resources_register (resource); file = g_file_new_for_uri ("resource://" "/a_prefix/test2-alias.txt"); - info = g_file_query_info (file, "*", 0, NULL, &error); g_assert_no_error (error); @@ -893,6 +892,37 @@ test_resource_64k (void) g_bytes_unref (data); } +/* Check that g_resources_get_info() respects G_RESOURCE_OVERLAYS */ +static void +test_overlay (void) +{ + if (g_test_subprocess ()) + { + GError *error = NULL; + gboolean res; + gsize size; + char *overlay; + char *path; + + path = g_test_build_filename (G_TEST_DIST, "test1.overlay", NULL); + overlay = g_strconcat ("/auto_loaded/test1.txt=", path, NULL); + + g_setenv ("G_RESOURCE_OVERLAYS", overlay, TRUE); + res = g_resources_get_info ("/auto_loaded/test1.txt", 0, &size, NULL, &error); + g_assert_true (res); + g_assert_no_error (error); + /* test1.txt is 6 bytes, test1.overlay is 23 */ + g_assert_cmpint (size, ==, 23); + + g_free (overlay); + g_free (path); + + return; + } + g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDERR); + g_test_trap_assert_passed (); +} + int main (int argc, char *argv[]) @@ -919,6 +949,7 @@ main (int argc, g_test_add_func ("/resource/uri/query-info", test_uri_query_info); g_test_add_func ("/resource/uri/file", test_uri_file); g_test_add_func ("/resource/64k", test_resource_64k); + g_test_add_func ("/resource/overlay", test_overlay); return g_test_run(); } diff --git a/gio/tests/test1.overlay b/gio/tests/test1.overlay new file mode 100644 index 000000000..687d69b2a --- /dev/null +++ b/gio/tests/test1.overlay @@ -0,0 +1 @@ +It is a beautiful day!