mirror of
https://github.com/profanity-im/profanity.git
synced 2024-10-27 20:30:13 -04:00
Resolve symlinks recursively in get_file_or_linked()
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
parent
d75b263b39
commit
b7f964fe64
13
src/common.c
13
src/common.c
@ -345,21 +345,20 @@ _data_callback(void* ptr, size_t size, size_t nmemb, void* data)
|
|||||||
gchar*
|
gchar*
|
||||||
get_file_or_linked(gchar* loc, gchar* basedir)
|
get_file_or_linked(gchar* loc, gchar* basedir)
|
||||||
{
|
{
|
||||||
gchar* true_loc = NULL;
|
gchar* true_loc = g_strdup(loc);
|
||||||
|
|
||||||
// check for symlink
|
// check for symlink
|
||||||
if (g_file_test(loc, G_FILE_TEST_IS_SYMLINK)) {
|
while (g_file_test(true_loc, G_FILE_TEST_IS_SYMLINK)) {
|
||||||
true_loc = g_file_read_link(loc, NULL);
|
gchar* tmp = g_file_read_link(true_loc, NULL);
|
||||||
|
g_free(true_loc);
|
||||||
|
true_loc = tmp;
|
||||||
|
|
||||||
// if relative, add basedir
|
// if relative, add basedir
|
||||||
if (!g_str_has_prefix(true_loc, "/") && !g_str_has_prefix(true_loc, "~")) {
|
if (!g_str_has_prefix(true_loc, "/") && !g_str_has_prefix(true_loc, "~")) {
|
||||||
gchar* tmp = g_strdup_printf("%s/%s", basedir, true_loc);
|
tmp = g_strdup_printf("%s/%s", basedir, true_loc);
|
||||||
g_free(true_loc);
|
g_free(true_loc);
|
||||||
true_loc = tmp;
|
true_loc = tmp;
|
||||||
}
|
}
|
||||||
// use given location
|
|
||||||
} else {
|
|
||||||
true_loc = g_strdup(loc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true_loc;
|
return true_loc;
|
||||||
|
Loading…
Reference in New Issue
Block a user