mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 07:38:54 +02:00
Merge branch 'master' into 'master'
gutils: ensure g_find_program_in_path() return an absolute path See merge request GNOME/glib!2127
This commit is contained in:
@@ -340,7 +340,17 @@ g_find_program_in_path (const gchar *program)
|
|||||||
{
|
{
|
||||||
if (g_file_test (program, G_FILE_TEST_IS_EXECUTABLE) &&
|
if (g_file_test (program, G_FILE_TEST_IS_EXECUTABLE) &&
|
||||||
!g_file_test (program, G_FILE_TEST_IS_DIR))
|
!g_file_test (program, G_FILE_TEST_IS_DIR))
|
||||||
return g_strdup (program);
|
{
|
||||||
|
gchar *out = NULL, *cwd = NULL;
|
||||||
|
|
||||||
|
if (g_path_is_absolute (program))
|
||||||
|
return g_strdup (program);
|
||||||
|
|
||||||
|
cwd = g_get_current_dir ();
|
||||||
|
out = g_build_filename (cwd, program, NULL);
|
||||||
|
g_free (cwd);
|
||||||
|
return g_steal_pointer (&out);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@@ -246,6 +246,11 @@ test_find_program (void)
|
|||||||
gchar *res;
|
gchar *res;
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
|
gchar *relative_path;
|
||||||
|
gchar *absolute_path;
|
||||||
|
gchar *cwd;
|
||||||
|
gsize i;
|
||||||
|
|
||||||
res = g_find_program_in_path ("sh");
|
res = g_find_program_in_path ("sh");
|
||||||
g_assert (res != NULL);
|
g_assert (res != NULL);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
@@ -253,6 +258,27 @@ test_find_program (void)
|
|||||||
res = g_find_program_in_path ("/bin/sh");
|
res = g_find_program_in_path ("/bin/sh");
|
||||||
g_assert (res != NULL);
|
g_assert (res != NULL);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
|
|
||||||
|
cwd = g_get_current_dir ();
|
||||||
|
absolute_path = g_find_program_in_path ("sh");
|
||||||
|
relative_path = g_strdup (absolute_path);
|
||||||
|
for (i = 0; cwd[i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
if (cwd[i] == '/' && cwd[i + 1] != '\0')
|
||||||
|
{
|
||||||
|
gchar *relative_path_2 = g_strconcat ("../", relative_path, NULL);
|
||||||
|
g_free (relative_path);
|
||||||
|
relative_path = relative_path_2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res = g_find_program_in_path (relative_path);
|
||||||
|
g_assert_nonnull (res);
|
||||||
|
g_assert_true (g_path_is_absolute (res));
|
||||||
|
g_free (cwd);
|
||||||
|
g_free (absolute_path);
|
||||||
|
g_free (relative_path);
|
||||||
|
g_free (res);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/* There's not a lot we can search for that would reliably work both
|
/* There's not a lot we can search for that would reliably work both
|
||||||
* on real Windows and mingw.
|
* on real Windows and mingw.
|
||||||
|
Reference in New Issue
Block a user