diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-02-23 18:49:20 +0100 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-02-23 18:49:20 +0100 |
commit | d92f5e23ddfd4a6b5bbeb9ff332e648d5d534658 (patch) | |
tree | 1d73751ed679d07fa121b61cbb1497904890cc10 | |
parent | 3e6ea0a46c929ac0a4072915058508316510fabd (diff) | |
download | ayatana-indicator-messages-d92f5e23ddfd4a6b5bbeb9ff332e648d5d534658.tar.gz ayatana-indicator-messages-d92f5e23ddfd4a6b5bbeb9ff332e648d5d534658.tar.bz2 ayatana-indicator-messages-d92f5e23ddfd4a6b5bbeb9ff332e648d5d534658.zip |
Use link targets as keys in the blacklist hash table
Fixes lp:939258
-rw-r--r-- | src/messages-service.c | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/src/messages-service.c b/src/messages-service.c index a21435c..a5ddaf4 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -321,26 +321,56 @@ desktop_file_from_keyfile (const gchar * definition_file) return desktopfile; } +static gchar * +get_symlink_target (const gchar *path, + GError **error) +{ + GFile *file; + GFileInfo *fileinfo; + gchar *target = NULL; + + file = g_file_new_for_path (path); + + fileinfo = g_file_query_info (file, "standard::*", + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, error); + g_object_unref (file); + + if (!fileinfo) + return NULL; + + if (!g_file_info_get_is_symlink (fileinfo) || + !(target = g_strdup (g_file_info_get_symlink_target (fileinfo)))) + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_NOT_SYMBOLIC_LINK, + "'%s' is not a symbolic link", + path); + } + + g_object_unref (fileinfo); + return target; +} + /* Add a definition file into the black list and eclipse any launchers that have the same file. */ static gboolean blacklist_add (gpointer udata) { gchar * definition_file = (gchar *)udata; - /* Dump the file */ - gchar * desktop; - g_file_get_contents(definition_file, &desktop, NULL, NULL); - if (desktop == NULL) { - g_warning("Couldn't get data out of: %s", definition_file); - return FALSE; - } + gchar * target; + GError *error = NULL; - /* Clean up the data */ - gchar * trimdesktop = pango_trim_string(desktop); - g_free(desktop); + target = get_symlink_target (definition_file, &error); + if (!target) { + g_warning ("Error loading blacklist file: %s", error->message); + g_error_free (error); + return FALSE; + } - blacklist_add_core(trimdesktop, definition_file); - g_free(trimdesktop); + blacklist_add_core(target, definition_file); + g_free(target); return FALSE; } |