[glib/wip/oholy/fix-trash-symlink: 4/5] glocalfile: Return NULL if symlink expansion fails
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/oholy/fix-trash-symlink: 4/5] glocalfile: Return NULL if symlink expansion fails
- Date: Mon, 1 Oct 2018 13:30:22 +0000 (UTC)
commit 3065f1980c3d2a6a91c44dadc038cf5d22231e1c
Author: Ondrej Holy <oholy redhat com>
Date: Fri Sep 21 17:02:05 2018 +0200
glocalfile: Return NULL if symlink expansion fails
find_mountpoint_for() uses current file in case of error, because
get_parent() returns NULL for error, but also if parent doesn't exist.
Return "." from get_parent() if parent doesn't exist in order to
differentiate the error state.
gio/glocalfile.c | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index 8fa7312f6..06d1ae58e 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -1634,15 +1634,11 @@ get_parent (const char *path,
path_copy = strip_trailing_slashes (path);
parent = g_path_get_dirname (path_copy);
- if (strcmp (parent, ".") == 0 ||
- strcmp (parent, path_copy) == 0)
- {
- g_free (parent);
- g_free (path_copy);
- return NULL;
- }
g_free (path_copy);
+ if (strcmp (parent, ".") == 0)
+ return parent;
+
res = expand_symlinks (parent, parent_dev);
g_free (parent);
@@ -1657,10 +1653,12 @@ expand_all_symlinks (const char *path)
dev_t parent_dev;
parent = get_parent (path, &parent_dev);
- if (parent)
+ if (parent == NULL)
+ return NULL;
+
+ if (g_strcmp0 (parent, ".") != 0)
{
parent_expanded = expand_all_symlinks (parent);
- g_free (parent);
basename = g_path_get_basename (path);
res = g_build_filename (parent_expanded, basename, NULL);
g_free (basename);
@@ -1668,7 +1666,9 @@ expand_all_symlinks (const char *path)
}
else
res = g_strdup (path);
-
+
+ g_free (parent);
+
return res;
}
@@ -1684,7 +1684,7 @@ find_mountpoint_for (const char *file,
{
dir = expand_symlinks (file, NULL);
if (dir == NULL)
- return g_strdup (file);
+ return NULL;
}
else
dir = g_strdup (file);
@@ -1695,8 +1695,17 @@ find_mountpoint_for (const char *file,
{
parent = get_parent (dir, &parent_dev);
if (parent == NULL)
- return dir;
-
+ {
+ g_free (dir);
+ return NULL;
+ }
+
+ if (g_strcmp0 (parent, ".") == 0)
+ {
+ g_free (parent);
+ return dir;
+ }
+
if (parent_dev != dir_dev)
{
g_free (parent);
@@ -1773,7 +1782,7 @@ try_make_relative (const char *path,
base2 = expand_all_symlinks (base);
relative = NULL;
- if (path_has_prefix (path2, base2))
+ if (path2 != NULL && base2 != NULL && path_has_prefix (path2, base2))
{
relative = path2 + strlen (base2);
while (*relative == '/')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]