diff options
author | Sam Thursfield <ssssam@gmail.com> | 2014-12-30 23:01:46 +0000 |
---|---|---|
committer | Sam Thursfield <ssssam@gmail.com> | 2014-12-31 00:27:24 +0000 |
commit | 8912a0995604462a3d7d8543cab4455591109318 (patch) | |
tree | c39c2e54ca953aa7097b7c0f9729d9a3676f3d02 | |
parent | e78956d83ea54bdd57f44ebe60e7330527131b5e (diff) | |
download | tracker-8912a0995604462a3d7d8543cab4455591109318.tar.gz |
miner-fs: Give clearer warning when XDG user dirs are unconfigured
If Tracker can't resolve special dirs like &DOCUMENTS to real path
names, it now gives a warning like this:
(tracker-miner-fs:7207): Tracker-WARNING **: Unable to get XDG user
directory path for special directory &DOCUMENTS. Ignoring this
location.
Previously (since commit 5f06c134f4f6da02027c813322e13c220b51cd0a) the
user would see this rather more scary output:
(tracker-miner-fs:6046): GLib-GIO-CRITICAL **: g_file_new_for_path:
assertion 'path != NULL' failed
(tracker-miner-fs:6046): GLib-GIO-CRITICAL **: g_file_equal: assertion
'G_IS_FILE (file1)' failed
(tracker-miner-fs:6046): GLib-GObject-CRITICAL **: g_object_unref:
assertion 'G_IS_OBJECT (object)' failed
This situation is rare (you need to manually change or break
XDG_CONFIG_HOME to really see it) but it's always nice to avoid showing
critical errors!
-rw-r--r-- | src/libtracker-common/tracker-file-utils.c | 65 | ||||
-rw-r--r-- | src/miners/fs/tracker-config.c | 44 |
2 files changed, 66 insertions, 43 deletions
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c index 22322d991..ad9f6b348 100644 --- a/src/libtracker-common/tracker-file-utils.c +++ b/src/libtracker-common/tracker-file-utils.c @@ -480,9 +480,67 @@ tracker_path_list_filter_duplicates (GSList *roots, return new_list; } +const struct { + const gchar *symbol; + GUserDirectory user_dir; +} special_dirs[] = { + {"&DESKTOP", G_USER_DIRECTORY_DESKTOP}, + {"&DOCUMENTS", G_USER_DIRECTORY_DOCUMENTS}, + {"&DOWNLOAD", G_USER_DIRECTORY_DOWNLOAD}, + {"&MUSIC", G_USER_DIRECTORY_MUSIC}, + {"&PICTURES", G_USER_DIRECTORY_PICTURES}, + {"&PUBLIC_SHARE", G_USER_DIRECTORY_PUBLIC_SHARE}, + {"&TEMPLATES", G_USER_DIRECTORY_TEMPLATES}, + {"&VIDEOS", G_USER_DIRECTORY_VIDEOS} +}; + + +static gchar * +get_user_special_dir_if_not_home (const gchar *path) +{ + int i; + const gchar *real_path; + GFile *home, *file; + gboolean res; + + real_path = NULL; + + for (i = 0; i < G_N_ELEMENTS(special_dirs); i++) { + if (strcmp (path, special_dirs[i].symbol) == 0) { + real_path = g_get_user_special_dir (special_dirs[i].user_dir); + + if (real_path == NULL) { + g_warning ("Unable to get XDG user directory path for special " + "directory %s. Ignoring this location.", path); + } + + break; + } + } + + if (real_path == NULL) + return NULL; + + file = g_file_new_for_path (real_path); + home = g_file_new_for_path (g_get_home_dir ()); + + res = g_file_equal (file, home); + g_object_unref (file); + g_object_unref (home); + + if (res) { + /* ignore XDG directories set to $HOME */ + return NULL; + } else { + return g_strdup (real_path); + } +} + + gchar * tracker_path_evaluate_name (const gchar *path) { + gchar *special_dir_path; gchar *final_path; gchar **tokens; gchar **token; @@ -495,6 +553,13 @@ tracker_path_evaluate_name (const gchar *path) return NULL; } + /* See if it is a special directory name. */ + special_dir_path = get_user_special_dir_if_not_home (path); + + if (special_dir_path != NULL) { + return special_dir_path; + } + /* First check the simple case of using tilder */ if (path[0] == '~') { const gchar *home; diff --git a/src/miners/fs/tracker-config.c b/src/miners/fs/tracker-config.c index 7d5f4b523..415b9004b 100644 --- a/src/miners/fs/tracker-config.c +++ b/src/miners/fs/tracker-config.c @@ -524,29 +524,6 @@ config_finalize (GObject *object) (G_OBJECT_CLASS (tracker_config_parent_class)->finalize) (object); } -static gchar * -get_user_special_dir_if_not_home (GUserDirectory directory) -{ - const gchar *path; - GFile *home, *file; - gboolean res; - - path = g_get_user_special_dir (directory); - file = g_file_new_for_path (path); - home = g_file_new_for_path (g_get_home_dir ()); - - res = g_file_equal (file, home); - g_object_unref (file); - g_object_unref (home); - - if (res) { - /* ignore XDG directories set to $HOME */ - return NULL; - } else { - return g_strdup (path); - } -} - static GSList * dir_mapping_get (GSList *dirs, gboolean is_recursive) @@ -563,26 +540,7 @@ dir_mapping_get (GSList *dirs, for (l = filtered; l; l = l->next) { gchar *path_to_use; - /* Must be a special dir */ - if (strcmp (l->data, "&DESKTOP") == 0) { - path_to_use = get_user_special_dir_if_not_home (G_USER_DIRECTORY_DESKTOP); - } else if (strcmp (l->data, "&DOCUMENTS") == 0) { - path_to_use = get_user_special_dir_if_not_home (G_USER_DIRECTORY_DOCUMENTS); - } else if (strcmp (l->data, "&DOWNLOAD") == 0) { - path_to_use = get_user_special_dir_if_not_home (G_USER_DIRECTORY_DOWNLOAD); - } else if (strcmp (l->data, "&MUSIC") == 0) { - path_to_use = get_user_special_dir_if_not_home (G_USER_DIRECTORY_MUSIC); - } else if (strcmp (l->data, "&PICTURES") == 0) { - path_to_use = get_user_special_dir_if_not_home (G_USER_DIRECTORY_PICTURES); - } else if (strcmp (l->data, "&PUBLIC_SHARE") == 0) { - path_to_use = get_user_special_dir_if_not_home (G_USER_DIRECTORY_PUBLIC_SHARE); - } else if (strcmp (l->data, "&TEMPLATES") == 0) { - path_to_use = get_user_special_dir_if_not_home (G_USER_DIRECTORY_TEMPLATES); - } else if (strcmp (l->data, "&VIDEOS") == 0) { - path_to_use = get_user_special_dir_if_not_home (G_USER_DIRECTORY_VIDEOS); - } else { - path_to_use = tracker_path_evaluate_name (l->data); - } + path_to_use = tracker_path_evaluate_name (l->data); if (path_to_use) { evaluated_dirs = g_slist_prepend (evaluated_dirs, path_to_use); |