[rygel] core: Don't use expired cache of description doc



commit 4598b9bf143b79881f4aff4350a6cd12275abd69
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Nov 17 19:08:48 2010 +0200

    core: Don't use expired cache of description doc
    
    If the template device description was modified after cached description
    was modified/created, use the template device description. Without this
    change, user had to manually remove the cached description documents each
    time we modified the templates.

 src/rygel/rygel-root-device-factory.vala |   32 ++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/src/rygel/rygel-root-device-factory.vala b/src/rygel/rygel-root-device-factory.vala
index 2f7541a..d611703 100644
--- a/src/rygel/rygel-root-device-factory.vala
+++ b/src/rygel/rygel-root-device-factory.vala
@@ -85,14 +85,7 @@ internal class Rygel.RootDeviceFactory {
     private XMLDoc create_desc (Plugin plugin,
                                 string desc_path,
                                 string template_path) throws GLib.Error {
-        XMLDoc doc;
-
-        if (this.check_path_exist (desc_path)) {
-            doc = new XMLDoc.from_path (desc_path);
-        } else {
-            /* Use the template */
-            doc = new XMLDoc.from_path (template_path);
-        }
+        var doc = this.get_latest_doc (desc_path, template_path);
 
         /* Modify description to include Plugin-specific stuff */
         this.prepare_desc_for_plugin (doc, plugin);
@@ -317,6 +310,29 @@ internal class Rygel.RootDeviceFactory {
         file.puts (mem.replace ("\n", ""));
     }
 
+    private XMLDoc get_latest_doc (string path1,
+                                   string path2) throws GLib.Error {
+        if (!check_path_exist (path1)) {
+            return new XMLDoc.from_path (path2);
+        }
+
+        var file = File.new_for_path (path1);
+        var info = file.query_info (FILE_ATTRIBUTE_TIME_MODIFIED,
+                                    FileQueryInfoFlags.NONE);
+        var mod1 = info.get_attribute_uint64 (FILE_ATTRIBUTE_TIME_MODIFIED);
+
+        file = File.new_for_path (path2);
+        info = file.query_info (FILE_ATTRIBUTE_TIME_MODIFIED,
+                                FileQueryInfoFlags.NONE);
+        var mod2 = info.get_attribute_uint64 (FILE_ATTRIBUTE_TIME_MODIFIED);
+
+        if (mod1 > mod2) {
+            return new XMLDoc.from_path (path1);
+        } else {
+            return new XMLDoc.from_path (path2);
+        }
+    }
+
     private bool check_path_exist (string path) {
         var file = File.new_for_path (path);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]