From 564b5157b51c99c201597b06fe6c9f02e62b94eb Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 4 Apr 2012 10:46:05 +0200 Subject: Revert blacklist changes make apps relying on old behavior work again The new policy is: if a file in the blacklist folder is a symbolic link, use its target. If its filename ends on .desktop, use the file's basename (so that copying files works). Otherwise, use the contents of file (first line should contain path to a desktop file). --- src/messages-service.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/messages-service.c b/src/messages-service.c index c975df1..26eaf78 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -321,14 +321,53 @@ desktop_file_from_keyfile (const gchar * definition_file) return desktopfile; } +/* Check if path is a symlink and return its target if it is */ +static gchar * +get_symlink_target (const gchar *path) +{ + GFile *file; + GFileInfo *fileinfo; + gchar *target = NULL; + + file = g_file_new_for_path (path); + + fileinfo = g_file_query_info (file, "standard::is-symlink", + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, NULL); + 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_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; - - blacklist_add_core(definition_file, definition_file); + gchar * symlink_target = get_symlink_target (definition_file); + gchar * contents = NULL; + + if (symlink_target) + blacklist_add_core (symlink_target, definition_file); + else if (g_str_has_suffix (definition_file, ".desktop")) + blacklist_add_core(definition_file, definition_file); + else if (g_file_get_contents (definition_file, &contents, NULL, NULL)) + { + gchar *trimmed = pango_trim_string (contents); + blacklist_add_core (trimmed, definition_file); + g_free (trimmed); + g_free (contents); + } + else + g_warning ("invalid blacklist entry: %s", definition_file); return FALSE; } -- cgit v1.2.3