From 9771039635bf8d1d2d7b98d019f0875146e77967 Mon Sep 17 00:00:00 2001
From: Ludovico de Nittis <ludovico.denittis@collabora.com>
Date: Wed, 17 Mar 2021 17:05:56 +0100
Subject: [PATCH] runtime: Try Exherbo's locale dirs as a fallback

When using Exherbo as the host system, the locales are located in
"/usr/${gnu_tuple}/lib/locale".

For this reason if we notice that the canonical "/usr/lib/locale" is
missing, we also try the Exherbo's paths before skipping it.

Partially addresses: #67

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

diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c
index b7cfeba60..5d52a36ed 100644
--- a/pressure-vessel/runtime.c
+++ b/pressure-vessel/runtime.c
@@ -3812,6 +3812,19 @@ pv_runtime_finish_libc_family (PvRuntime *self,
   g_autofree gchar *locale = NULL;
   GHashTableIter iter;
   const gchar *gconv_path;
+  gsize i;
+  /* List of paths where we expect to find "locale", sorted by the most
+   * preferred to the least preferred.
+   * If the canonical "/usr/lib/locale" is missing, we try the Exherbo's
+   * "/usr/${gnu_tuple}/lib/locale" too, before giving up.
+   * The locale directory is actually architecture-independent, so we just
+   * arbitrarily prefer to use "x86_64-pc-linux-gnu" over the 32-bit couterpart */
+  const gchar *lib_locale_path[] = {
+    "/usr/lib/locale",
+    "/usr/x86_64-pc-linux-gnu/lib/locale",
+    "/usr/i686-pc-linux-gnu/lib/locale",
+    NULL
+  };
 
   g_return_val_if_fail (self->flags & PV_RUNTIME_FLAGS_PROVIDER_GRAPHICS_STACK, FALSE);
   g_return_val_if_fail (bwrap != NULL || self->mutable_sysroot != NULL, FALSE);
@@ -3838,12 +3851,21 @@ pv_runtime_finish_libc_family (PvRuntime *self,
     {
       g_debug ("Making provider locale data visible in container");
 
-      if (!pv_runtime_take_from_provider (self, bwrap,
-                                          "/usr/lib/locale",
-                                          "/usr/lib/locale",
-                                          TAKE_FROM_PROVIDER_FLAGS_IF_EXISTS,
-                                          error))
-        return FALSE;
+      for (i = 0; i < G_N_ELEMENTS (lib_locale_path) - 1; i++)
+        {
+          if (_srt_file_test_in_sysroot (self->provider_in_current_namespace, -1,
+                                         lib_locale_path[i], G_FILE_TEST_EXISTS))
+            {
+              if (!pv_runtime_take_from_provider (self, bwrap,
+                                                  lib_locale_path[i],
+                                                  "/usr/lib/locale",
+                                                  TAKE_FROM_PROVIDER_FLAGS_IF_EXISTS,
+                                                  error))
+                return FALSE;
+
+              break;
+            }
+        }
 
       if (!pv_runtime_take_from_provider (self, bwrap,
                                           "/usr/share/i18n",
-- 
GitLab