From 62e6a751886e1030fa0d4d062fde009c67a6a544 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Thu, 5 May 2011 15:45:25 +0200 Subject: dconf update: support lockdown --- bin/dconf-update.vala | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/bin/dconf-update.vala b/bin/dconf-update.vala index a30ce4b..0eaf728 100644 --- a/bin/dconf-update.vala +++ b/bin/dconf-update.vala @@ -41,6 +41,38 @@ unowned Gvdb.Item get_parent (Gvdb.HashTable table, string name) { return parent; } +Gvdb.HashTable? read_locks_directory (string dirname) throws GLib.Error { + var dir = Dir.open (dirname); + + if (dir == null) { + return null; + } + + var table = new Gvdb.HashTable (); + unowned string? name; + + while ((name = dir.read_name ()) != null) { + var filename = Path.build_filename (dirname, name); + Posix.Stat buf; + + // only 'normal' files + if (Posix.stat (filename, out buf) < 0 || !Posix.S_ISREG (buf.st_mode)) { + continue; + } + + string contents; + FileUtils.get_contents (filename, out contents, null); + + foreach (var line in contents.split ("\n")) { + if (line.has_prefix ("/")) { + table.insert (line); + } + } + } + + return table; +} + Gvdb.HashTable read_directory (string dirname) throws GLib.Error { var table = new Gvdb.HashTable (); unowned string? name; @@ -101,6 +133,13 @@ Gvdb.HashTable read_directory (string dirname) throws GLib.Error { } } + var locks = read_locks_directory (dirname + "/locks"); + + if (locks != null) { + unowned Gvdb.Item item = table.insert (".locks"); + item.set_hash_table (locks); + } + return table; } -- cgit v1.2.1