1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
From: Simon McVittie <smcv@debian.org>
Date: Thu, 14 Oct 2021 00:31:33 +0100
Subject: languages: Look at $LOCPATH before compile-time LIBLOCALEDIR
This allows unit testing on a minimal system with no locales set up, by
generating some locales in a directory and setting LOCPATH.
Signed-off-by: Simon McVittie <smcv@debian.org>
---
libgnome-desktop/gnome-languages.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
index 47456a0..1e91dcb 100644
--- a/libgnome-desktop/gnome-languages.c
+++ b/libgnome-desktop/gnome-languages.c
@@ -441,8 +441,15 @@ add_locale (const char *language_name,
static int
select_dirs (const struct dirent *dirent)
{
+ const char *locpath;
int result = 0;
+ locpath = g_getenv ("LOCPATH");
+
+ if (locpath == NULL) {
+ locpath = LIBLOCALEDIR;
+ }
+
if (strcmp (dirent->d_name, ".") != 0 && strcmp (dirent->d_name, "..") != 0) {
mode_t mode = 0;
@@ -455,7 +462,7 @@ select_dirs (const struct dirent *dirent)
struct stat st;
g_autofree char *path = NULL;
- path = g_build_filename (LIBLOCALEDIR, dirent->d_name, NULL);
+ path = g_build_filename (locpath, dirent->d_name, NULL);
if (g_stat (path, &st) == 0) {
mode = st.st_mode;
}
@@ -474,8 +481,15 @@ collect_locales_from_directory (void)
struct dirent **dirents;
int ndirents;
int cnt;
+ const char *locpath;
+
+ locpath = g_getenv ("LOCPATH");
+
+ if (locpath == NULL) {
+ locpath = LIBLOCALEDIR;
+ }
- ndirents = scandir (LIBLOCALEDIR, &dirents, select_dirs, alphasort);
+ ndirents = scandir (locpath, &dirents, select_dirs, alphasort);
for (cnt = 0; cnt < ndirents; ++cnt) {
if (add_locale (dirents[cnt]->d_name, TRUE))
|