[PATCH 2/3] On older accounts, special XDG directories don't always exist. It may be rude (in this context) to create them, but it is certainly rude to silently segfault as well.



Creating a new static method, to look for alternative directories before
giving up.

Security Notice: silently falling back on indexing and exporting the whole
$HOME or $TMP may be a security/privacy issue; but it is probably not much
worse than silently and unconditionnally indexing the XDG magic directories
anyway.

Signed-off-by: Cyrille Chepelov <cyrille chepelov keyconsulting fr>
---
 .../tracker/rygel-tracker-item-factory.vala        |   25 ++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/plugins/tracker/rygel-tracker-item-factory.vala b/src/plugins/tracker/rygel-tracker-item-factory.vala
index 1a7537c..04e8772 100644
--- a/src/plugins/tracker/rygel-tracker-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-item-factory.vala
@@ -44,6 +44,31 @@ public abstract class Rygel.TrackerItemFactory {
 
     public ArrayList<ArrayList<string>> key_chains;
 
+    /** 
+      *	returns the user's XDG specific directory, if this is set up
+      * if it fails, the desktop directory
+      * if that fails too, the temporary directory. Our constructor
+      * will violently disagree if no valid directory is found 
+      */
+    protected static string get_safe_user_special_dir(UserDirectory user_directory) {
+ 	string result = Environment.get_user_special_dir (user_directory);
+	if (result != null) return result;
+
+	warning("UserDirectory %u not found, attempting a fallback on DESKTOP...", user_directory);
+
+	result = Environment.get_user_special_dir(UserDirectory.DESKTOP);
+	if (result != null) return result;
+
+	warning("UserDirectory.DESKTOP not found, attempting a fallback on the Temporary Directory...");
+
+	result = Environment.get_tmp_dir();
+	if (result != null) return result;
+
+	error("No valid fallback found :( ");
+
+	assert_not_reached();
+    }
+
     public TrackerItemFactory (string category,
                                string upnp_class,
                                string resources_class_path,
-- 
1.6.6.1


--=-JyxFSry9bNuTYyGYB888
Content-Disposition: attachment; filename="0003-Avoid-segfaulting-on-legacy-accounts-where-the-XDG.patch"
Content-Type: text/x-patch; name="0003-Avoid-segfaulting-on-legacy-accounts-where-the-XDG.patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit



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