glib2/backport-Fix-giomodule-cache-being-wrongly-considered-stale.patch
shirely16 a3d31ddf3c synchronous community patch
(cherry picked from commit 5fb95aa15490a21b390e53a88c1b8b052971e504)
2021-05-21 15:56:45 +08:00

82 lines
3.3 KiB
Diff

From 497c511a984d8c71b3ea48e4f5cfc2537b907021 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9o=20Stefanesco?= <leo.lveb@gmail.com>
Date: Fri, 3 Jul 2020 15:16:33 +0200
Subject: [PATCH 0698/1095] Fix giomodule.cache being wrongly considered stale
In ostree based systems, such as flatpak and fedora silverblue, the
time of modification of every system file is epoch 0, including
giomodule.cache, which means that every module is loaded and unloaded
every time.
The solution is to use the change time of the file as well. In a typical
system, it is equal to the mtime, and in an ostree based system, since
the directory is mounted as read-only, the user cannot add a module and
we must assume that the cache file corresponds to the modules.
reason:Fix giomodule.cache being wrongly considered stale
Conflict:NA
Reference:https://github.com/GNOME/glib/commit/497c511a984d8c71b3ea48e4f5cfc2537b907021
---
gio/giomodule.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/gio/giomodule.c b/gio/giomodule.c
index f49ea3e..d8d64be 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -462,7 +462,7 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname,
GDir *dir;
GStatBuf statbuf;
char *data;
- time_t cache_mtime;
+ time_t cache_time;
GHashTable *cache;
if (!g_module_supported ())
@@ -477,21 +477,24 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname,
cache = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify)g_strfreev);
- cache_mtime = 0;
+ cache_time = 0;
if (g_stat (filename, &statbuf) == 0 &&
g_file_get_contents (filename, &data, NULL, NULL))
{
char **lines;
int i;
- /* Cache mtime is the time the cache file was created, any file
- * that has a ctime before this was created then and not modified
- * since then (userspace can't change ctime). Its possible to change
- * the ctime forward without changing the file content, by e.g.
- * chmoding the file, but this is uncommon and will only cause us
- * to not use the cache so will not cause bugs.
+ /* cache_time is the time the cache file was created; we also take
+ * into account the change time because in ostree based systems, all
+ * system file have mtime equal to epoch 0.
+ *
+ * Any file that has a ctime before this was created then and not modified
+ * since then (userspace can't change ctime). Its possible to change the
+ * ctime forward without changing the file content, by e.g. chmoding the
+ * file, but this is uncommon and will only cause us to not use the cache
+ * so will not cause bugs.
*/
- cache_mtime = statbuf.st_mtime;
+ cache_time = MAX(statbuf.st_mtime, statbuf.st_ctime);
lines = g_strsplit (data, "\n", -1);
g_free (data);
@@ -539,7 +542,7 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname,
extension_points = g_hash_table_lookup (cache, name);
if (extension_points != NULL &&
g_stat (path, &statbuf) == 0 &&
- statbuf.st_ctime <= cache_mtime)
+ statbuf.st_ctime <= cache_time)
{
/* Lazy load/init the library when first required */
for (i = 0; extension_points[i] != NULL; i++)
--
1.8.3.1