From 8d59690153112b7416648c9769891767175f4133 Mon Sep 17 00:00:00 2001
From: Ludovico de Nittis <ludovico.denittis@collabora.com>
Date: Fri, 9 Apr 2021 14:20:05 +0200
Subject: [PATCH] runtime: Search gconv in the correct dir when it starts with
 /app

When we search for gconv in the provider, if the directory we derived
from libc starts with "/app/", we should not prepend "/usr/" because we
don't expect to have "/usr/app/" in the provider.

Without this patch, pressure-vessel in a Flatpak container fails to load
i386 gconv with the following message:
"We were expecting the gconv modules directory in the provider to be
located in "/app/lib/i386-linux-gnu/gconv", but instead it is missing"

Fixes: T27437

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
---
 pressure-vessel/runtime.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c
index ae3595d86..a3a331863 100644
--- a/pressure-vessel/runtime.c
+++ b/pressure-vessel/runtime.c
@@ -3620,7 +3620,12 @@ pv_runtime_collect_libc_family (PvRuntime *self,
       if (g_str_has_prefix (dir, "/usr/"))
         memmove (dir, dir + strlen ("/usr"), strlen (dir) - strlen ("/usr") + 1);
 
-      gconv_dir_in_provider = g_build_filename ("/usr", dir, "gconv", NULL);
+      /* If it starts with "/app/" we don't prepend "/usr/" because we don't
+       * expect "/usr/app/" to be available */
+      if (g_str_has_prefix (dir, "/app/"))
+        gconv_dir_in_provider = g_build_filename (dir, "gconv", NULL);
+      else
+        gconv_dir_in_provider = g_build_filename ("/usr", dir, "gconv", NULL);
 
       if (_srt_file_test_in_sysroot (self->provider_in_current_namespace,
                                      -1,
@@ -3652,7 +3657,10 @@ pv_runtime_collect_libc_family (PvRuntime *self,
             }
 
           g_clear_pointer (&gconv_dir_in_provider, g_free);
-          gconv_dir_in_provider = g_build_filename ("/usr", dir, "gconv", NULL);
+          if (g_str_has_prefix (dir, "/app/"))
+            gconv_dir_in_provider = g_build_filename (dir, "gconv", NULL);
+          else
+            gconv_dir_in_provider = g_build_filename ("/usr", dir, "gconv", NULL);
 
           if (_srt_file_test_in_sysroot (self->provider_in_current_namespace,
                                          -1,
-- 
GitLab