summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorentin Noël <corentin.noel@collabora.com>2019-04-05 15:44:40 +0200
committerAlberto Fanjul <albertofanjul@gmail.com>2019-06-09 20:16:27 +0200
commit1980767aae0872e19634656f98de7408493b141e (patch)
tree020556878daee706b7f40d0d907683a45b0a75d7
parentb108afa29b2b4d26c124920e7c71f716c2c201e4 (diff)
downloadglade-1980767aae0872e19634656f98de7408493b141e.tar.gz
Utils: get the absolute path but avoid accessing it
It's not working on Flatpak
-rw-r--r--gladeui/glade-utils.c51
1 files changed, 8 insertions, 43 deletions
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 0e0560c7..d83e780d 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -775,7 +775,7 @@ glade_util_find_iter_by_widget (GtkTreeModel *model,
/**
* glade_util_purify_list: (skip)
- * @list: A #GList
+ * @list: (transfer full): A #GList
*
* Returns: (transfer full): A newly allocated version of @list with no
* duplicate data entries
@@ -799,7 +799,7 @@ glade_util_purify_list (GList * list)
* @old_list: the old #GList
* @new_list: the new #GList
*
- * Returns: (transfer full): A newly allocated #GList of elements that
+ * Returns: (transfer container): A newly allocated #GList of elements that
* are in @new but not in @old
*
*/
@@ -822,7 +822,7 @@ glade_util_added_in_list (GList *old_list, GList *new_list)
* @old_list: the old #GList
* @new_list: the new #GList
*
- * Returns: (transfer full): A newly allocated #GList of elements that
+ * Returns: (transfer container): A newly allocated #GList of elements that
* are in @old no longer in @new
*
*/
@@ -848,54 +848,19 @@ glade_util_removed_from_list (GList *old_list, GList *new_list)
* Returns: an absolute path to the specified file or directory
* that contains no ".." or "." components (this does
* not call readlink like realpath() does).
- *
- * Note: on some systems; I think its possible that we dont have
- * permission to execute in the directory in which the glade
- * file resides; I decided finally to do it this way anyway
- * since libc's realpath() does exactly the same.
*/
gchar *
glade_util_canonical_path (const gchar *path)
{
- gchar *orig_dir, *dirname, *basename, *direct_dir, *direct_name = NULL;
+ GFile *file;
+ gchar *direct_name;
g_return_val_if_fail (path != NULL, NULL);
- basename = g_path_get_basename (path);
-
- if ((orig_dir = g_get_current_dir ()) != NULL)
- {
- if ((dirname = g_path_get_dirname (path)) != NULL)
- {
- if (g_chdir (dirname) == 0)
- {
- if ((direct_dir = g_get_current_dir ()) != NULL)
- {
- direct_name = g_build_filename (direct_dir, basename, NULL);
- g_free (direct_dir);
- }
- else
- g_warning ("g_path");
-
- if (g_chdir (orig_dir) != 0)
- g_warning ("Unable to chdir back to %s directory (%s)",
- orig_dir, g_strerror (errno));
-
- }
- else
- g_warning ("Unable to chdir to %s directory (%s)",
- dirname, g_strerror (errno));
-
- g_free (dirname);
- }
- else
- g_warning ("Unable to get directory component of %s\n", path);
- g_free (orig_dir);
- }
-
- if (basename)
- g_free (basename);
+ file = g_file_new_for_path (path);
+ direct_name = g_file_get_path (file);
+ g_object_unref (file);
return direct_name;
}