run: Create symlinks as relative paths to make them work during bwrap setup

During setup the new root is in /newroot, so absolute symlinks don't work.
We make them realtive so that we can resolve the symlinks during setup.

(cherry picked from commit b1dd1c3f7a865f39ef9f296e3a0f96304f96247c)
This commit is contained in:
Alexander Larsson committed 2017-01-19 15:33:43 +01:00
1 parent d24b862a50
commit 1851df22e4
1 file changed
+28 -1
+28 -1
View File
@@ -2207,6 +2207,31 @@ flatpak_run_add_extension_args (GPtrArray *argv_array,
return TRUE;
}
static char *
make_relative (const char *base, const char *path)
{
GString *s = g_string_new ("");
while (*base != 0)
{
while (*base == '/')
base++;
if (*base != 0)
g_string_append (s, "../");
while (*base != '/' && *base != 0)
base++;
}
while (*path == '/')
path++;
g_string_append (s, path);
return g_string_free (s, FALSE);
}
#define FAKE_MODE_HIDDEN 0
#define FAKE_MODE_SYMLINK G_MAXINT
@@ -2260,8 +2285,10 @@ add_file_args (GPtrArray *argv_array,
if (!path_is_visible (keys, n_keys, hash_table, path))
{
g_autofree char *resolved = flatpak_resolve_link (path, NULL);
g_autofree char *parent = g_path_get_dirname (path);
g_autofree char *relative = make_relative (parent, resolved);
if (resolved)
add_args (argv_array, "--symlink", resolved, path, NULL);
add_args (argv_array, "--symlink", relative, path, NULL);
}
}
else if (mode == FAKE_MODE_HIDDEN)