[tracker/wip/sam/meson] sandbox: Fix MIME-type detection inside the sandbox



commit ad7b93a1611d3eb486fb495507c3539f9d144bcc
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Jun 13 16:28:30 2016 +0100

    sandbox: Fix MIME-type detection inside the sandbox
    
    It turns out that MIME-type detection depends on various files in
    $XDG_DATA_HOME/mime, at least on my Fedora 24 system.
    
    We need to link to these files in our overridden XDG_DATA_HOME dir if we
    want extraction to work properly, otherwise everything is detected as
    text/plain.

 utils/sandbox/tracker-sandbox.py |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/utils/sandbox/tracker-sandbox.py b/utils/sandbox/tracker-sandbox.py
index 42d0e33..abfb05b 100755
--- a/utils/sandbox/tracker-sandbox.py
+++ b/utils/sandbox/tracker-sandbox.py
@@ -78,6 +78,8 @@ dbus_session_file = ''
 store_pid = -1
 store_proc = None
 
+original_xdg_data_home = GLib.get_user_data_dir()
+
 # Template config file
 config_template = """
 [General]
@@ -399,6 +401,22 @@ def config_set():
                config.write(f)
 
 
+def link_to_mime_data():
+       '''Create symlink to $XDG_DATA_HOME/mime in our custom data home dir.
+
+       Mimetype detection seems to break horribly if the $XDG_DATA_HOME/mime
+       directory is missing. Since we have to override the normal XDG_DATA_HOME
+       path, we need to work around this by linking back to the real mime data.
+
+       '''
+       new_xdg_data_home = os.environ['XDG_DATA_HOME']
+       new_mime_dir = os.path.join(new_xdg_data_home, 'mime')
+       if not os.path.exists(new_mime_dir):
+               mkdir_p(new_xdg_data_home)
+               os.symlink(
+                       os.path.join(original_xdg_data_home, 'mime'), new_mime_dir)
+
+
 # Entry point/start
 if __name__ == "__main__":
        locale.setlocale(locale.LC_ALL, '')
@@ -493,6 +511,8 @@ if __name__ == "__main__":
        environment_set()
        config_set()
 
+       link_to_mime_data()
+
        try:
                if opts.update:
                        index_update()


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