c7e794
From 6a6797446f13378035a2700253546b524d629c8a Mon Sep 17 00:00:00 2001
c7e794
From: Marek Kasik <mkasik@redhat.com>
c7e794
Date: Tue, 10 Jul 2018 18:29:16 +0200
c7e794
Subject: [PATCH] Check mtimes of files when updating databases
c7e794
c7e794
Do not check just mtimes of directories in /etc/dconf/db/
c7e794
but also mtimes of the files in those directories
c7e794
to catch all modifications in them.
c7e794
c7e794
https://bugzilla.gnome.org/show_bug.cgi?id=708258
c7e794
---
c7e794
 bin/dconf-update.vala | 41 ++++++++++++++++++++++++++++++++++-------
c7e794
 1 file changed, 34 insertions(+), 7 deletions(-)
c7e794
c7e794
diff --git a/bin/dconf-update.vala b/bin/dconf-update.vala
c7e794
index d452092..5aac6c7 100644
c7e794
--- a/bin/dconf-update.vala
c7e794
+++ b/bin/dconf-update.vala
c7e794
@@ -162,21 +162,48 @@ Gvdb.HashTable read_directory (string dirname) throws GLib.Error {
c7e794
 	return table;
c7e794
 }
c7e794
 
c7e794
+time_t get_directory_mtime (string dirname, Posix.Stat dir_buf) throws GLib.Error {
c7e794
+	Posix.Stat lockdir_buf;
c7e794
+	Posix.Stat file_buf;
c7e794
+	time_t dir_mtime = dir_buf.st_mtime;
c7e794
+
c7e794
+	var files = list_directory (dirname, Posix.S_IFREG);
c7e794
+	files.sort (strcmp);
c7e794
+	files.reverse ();
c7e794
+
c7e794
+	foreach (var filename in files) {
c7e794
+		if (Posix.stat (filename, out file_buf) == 0 && file_buf.st_mtime > dir_mtime)
c7e794
+			dir_mtime = file_buf.st_mtime;
c7e794
+	}
c7e794
+
c7e794
+	if (Posix.stat (dirname + "/locks", out lockdir_buf) == 0 && Posix.S_ISDIR (lockdir_buf.st_mode)) {
c7e794
+		if (lockdir_buf.st_mtime > dir_mtime) {
c7e794
+			// if the lock directory has been updated more recently then consider its timestamp instead
c7e794
+			dir_mtime = lockdir_buf.st_mtime;
c7e794
+		}
c7e794
+
c7e794
+		files = list_directory (dirname + "/locks", Posix.S_IFREG);
c7e794
+		files.sort (strcmp);
c7e794
+		files.reverse ();
c7e794
+
c7e794
+		foreach (var filename in files) {
c7e794
+			if (Posix.stat (filename, out file_buf) == 0 && file_buf.st_mtime > dir_mtime)
c7e794
+				dir_mtime = file_buf.st_mtime;
c7e794
+		}
c7e794
+	}
c7e794
+
c7e794
+	return dir_mtime;
c7e794
+}
c7e794
+
c7e794
 void maybe_update_from_directory (string dirname) throws GLib.Error {
c7e794
 	Posix.Stat dir_buf;
c7e794
 
c7e794
 	if (Posix.stat (dirname, out dir_buf) == 0 && Posix.S_ISDIR (dir_buf.st_mode)) {
c7e794
-		Posix.Stat lockdir_buf;
c7e794
 		Posix.Stat file_buf;
c7e794
 
c7e794
 		var filename = dirname.substring (0, dirname.length - 2);
c7e794
 
c7e794
-		if (Posix.stat (dirname + "/locks", out lockdir_buf) == 0 && lockdir_buf.st_mtime > dir_buf.st_mtime) {
c7e794
-			// if the lock directory has been updated more recently then consider its timestamp instead
c7e794
-			dir_buf.st_mtime = lockdir_buf.st_mtime;
c7e794
-		}
c7e794
-
c7e794
-		if (Posix.stat (filename, out file_buf) == 0 && file_buf.st_mtime > dir_buf.st_mtime) {
c7e794
+		if (Posix.stat (filename, out file_buf) == 0 && file_buf.st_mtime > get_directory_mtime (dirname, dir_buf)) {
c7e794
 			return;
c7e794
 		}
c7e794
 
c7e794
-- 
c7e794
2.17.1
c7e794