summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Kašík <mkasik@redhat.com>2018-11-28 15:15:50 +0000
committerMarek Kašík <mkasik@redhat.com>2018-11-28 15:15:50 +0000
commite2dfc6864497fedab68df8dc53056fa3fadbb481 (patch)
tree41b885f540d15d7b709e71c07b207dd1cbc60043
parent725bc9756236996f3ff00bc8f7545b8f7c24b789 (diff)
parent7e23a5a9ad9db3b4d313d641cd51bb619713773c (diff)
downloaddconf-e2dfc6864497fedab68df8dc53056fa3fadbb481.tar.gz
Merge branch '011-dconf-update-is-not-correctly-checking-the-mtime-of-the-keyfiles' into 'master'
Check mtimes of files when updating databases Closes #11 See merge request GNOME/dconf!27
-rw-r--r--bin/dconf-update.vala37
1 files changed, 30 insertions, 7 deletions
diff --git a/bin/dconf-update.vala b/bin/dconf-update.vala
index 520e02d..149e8fe 100644
--- a/bin/dconf-update.vala
+++ b/bin/dconf-update.vala
@@ -162,21 +162,44 @@ Gvdb.HashTable read_directory (string dirname) throws GLib.Error {
return table;
}
+time_t get_directory_mtime (string dirname, Posix.Stat dir_buf) throws GLib.Error {
+ Posix.Stat lockdir_buf;
+ Posix.Stat file_buf;
+ time_t latest_mtime = dir_buf.st_mtime;
+
+ var files = list_directory (dirname, Posix.S_IFREG);
+
+ foreach (var filename in files) {
+ if (Posix.stat (filename, out file_buf) == 0 && file_buf.st_mtime > latest_mtime)
+ latest_mtime = file_buf.st_mtime;
+ }
+
+ if (Posix.stat (dirname + "/locks", out lockdir_buf) == 0 && Posix.S_ISDIR (lockdir_buf.st_mode)) {
+ if (lockdir_buf.st_mtime > latest_mtime) {
+ // if the lock directory has been updated more recently then consider its timestamp instead
+ latest_mtime = lockdir_buf.st_mtime;
+ }
+
+ files = list_directory (dirname + "/locks", Posix.S_IFREG);
+
+ foreach (var filename in files) {
+ if (Posix.stat (filename, out file_buf) == 0 && file_buf.st_mtime > latest_mtime)
+ latest_mtime = file_buf.st_mtime;
+ }
+ }
+
+ return latest_mtime;
+}
+
void maybe_update_from_directory (string dirname) throws GLib.Error {
Posix.Stat dir_buf;
if (Posix.stat (dirname, out dir_buf) == 0 && Posix.S_ISDIR (dir_buf.st_mode)) {
- Posix.Stat lockdir_buf;
Posix.Stat file_buf;
var filename = dirname.substring (0, dirname.length - 2);
- if (Posix.stat (dirname + "/locks", out lockdir_buf) == 0 && lockdir_buf.st_mtime > dir_buf.st_mtime) {
- // if the lock directory has been updated more recently then consider its timestamp instead
- dir_buf.st_mtime = lockdir_buf.st_mtime;
- }
-
- if (Posix.stat (filename, out file_buf) == 0 && file_buf.st_mtime > dir_buf.st_mtime) {
+ if (Posix.stat (filename, out file_buf) == 0 && file_buf.st_mtime > get_directory_mtime (dirname, dir_buf)) {
return;
}