mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-03 22:52:09 +01:00
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.
This commit is contained in:
parent
57cfbc9341
commit
b6191059b8
@ -1634,8 +1634,7 @@ get_parent (const char *path,
|
|||||||
path_copy = strip_trailing_slashes (path);
|
path_copy = strip_trailing_slashes (path);
|
||||||
|
|
||||||
parent = g_path_get_dirname (path_copy);
|
parent = g_path_get_dirname (path_copy);
|
||||||
if (strcmp (parent, ".") == 0 ||
|
if (strcmp (parent, ".") == 0)
|
||||||
strcmp (parent, path_copy) == 0)
|
|
||||||
{
|
{
|
||||||
g_free (parent);
|
g_free (parent);
|
||||||
g_free (path_copy);
|
g_free (path_copy);
|
||||||
@ -1657,10 +1656,12 @@ expand_all_symlinks (const char *path)
|
|||||||
dev_t parent_dev;
|
dev_t parent_dev;
|
||||||
|
|
||||||
parent = get_parent (path, &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);
|
parent_expanded = expand_all_symlinks (parent);
|
||||||
g_free (parent);
|
|
||||||
basename = g_path_get_basename (path);
|
basename = g_path_get_basename (path);
|
||||||
res = g_build_filename (parent_expanded, basename, NULL);
|
res = g_build_filename (parent_expanded, basename, NULL);
|
||||||
g_free (basename);
|
g_free (basename);
|
||||||
@ -1669,6 +1670,8 @@ expand_all_symlinks (const char *path)
|
|||||||
else
|
else
|
||||||
res = g_strdup (path);
|
res = g_strdup (path);
|
||||||
|
|
||||||
|
g_free (parent);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1684,18 +1687,21 @@ find_mountpoint_for (const char *file,
|
|||||||
{
|
{
|
||||||
dir = expand_symlinks (file, NULL);
|
dir = expand_symlinks (file, NULL);
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
return g_strdup (file);
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dir = g_strdup (file);
|
dir = g_strdup (file);
|
||||||
|
|
||||||
dir_dev = dev;
|
dir_dev = dev;
|
||||||
|
|
||||||
while (1)
|
while (g_strcmp0 (dir, "/") != 0)
|
||||||
{
|
{
|
||||||
parent = get_parent (dir, &parent_dev);
|
parent = get_parent (dir, &parent_dev);
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
return dir;
|
{
|
||||||
|
g_free (dir);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (parent_dev != dir_dev)
|
if (parent_dev != dir_dev)
|
||||||
{
|
{
|
||||||
@ -1706,6 +1712,8 @@ find_mountpoint_for (const char *file,
|
|||||||
g_free (dir);
|
g_free (dir);
|
||||||
dir = parent;
|
dir = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
@ -1773,7 +1781,7 @@ try_make_relative (const char *path,
|
|||||||
base2 = expand_all_symlinks (base);
|
base2 = expand_all_symlinks (base);
|
||||||
|
|
||||||
relative = NULL;
|
relative = NULL;
|
||||||
if (path_has_prefix (path2, base2))
|
if (path2 != NULL && base2 != NULL && path_has_prefix (path2, base2))
|
||||||
{
|
{
|
||||||
relative = path2 + strlen (base2);
|
relative = path2 + strlen (base2);
|
||||||
while (*relative == '/')
|
while (*relative == '/')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user