File: fix-locale-path.diff

package info (click to toggle)
rust-coreutils 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 485,976 kB
  • sloc: ansic: 103,608; asm: 28,570; sh: 8,672; python: 5,662; makefile: 474; cpp: 97; javascript: 72
file content (195 lines) | stat: -rw-r--r-- 7,232 bytes parent folder | download
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
Index: coreutils/GNUmakefile
===================================================================
--- coreutils.orig/GNUmakefile
+++ coreutils/GNUmakefile
@@ -34,6 +34,7 @@ PREFIX ?= /usr
 DESTDIR ?=
 BINDIR ?= $(PREFIX)/bin
 DATAROOTDIR ?= $(PREFIX)/share
+LOCALEDIR ?= $(DATAROOTDIR)/coreutils/locales
 LIBSTDBUF_DIR ?= $(PREFIX)/libexec/$(PROG_PREFIX)coreutils
 # Export variable so that it is used during the build
 export LIBSTDBUF_DIR
@@ -244,7 +245,7 @@ endif
 
 ifeq ($(LOCALES),y)
 locales:
-	@# Copy uucore common locales
+	# Copy uucore common locales
 	@if [ -d "$(BASEDIR)/src/uucore/locales" ]; then \
 		mkdir -p "$(BUILDDIR)/locales/uucore"; \
 		for locale_file in "$(BASEDIR)"/src/uucore/locales/*.ftl; do \
@@ -265,16 +266,23 @@ locales:
 
 
 install-locales:
-	@for prog in $(INSTALLEES); do \
+	@mkdir -p "$(DESTDIR)$(LOCALEDIR)/uucore/"; \
+	for locale_file in "$(BASEDIR)"/src/uucore/locales/*.ftl; do \
+		if [ "$$(basename "$$locale_file")" != "en-US.ftl" ]; then \
+			$(INSTALL) -v -m 644 "$$locale_file" "$(DESTDIR)$(LOCALEDIR)/uucore/"; \
+		fi; \
+	done;
+	for prog in $(INSTALLEES); do \
 		if [ -d "$(BASEDIR)/src/uu/$$prog/locales" ]; then \
-			mkdir -p "$(DESTDIR)$(DATAROOTDIR)/locales/$$prog"; \
+			mkdir -p "$(DESTDIR)$(LOCALEDIR)/$$prog"; \
 			for locale_file in "$(BASEDIR)"/src/uu/$$prog/locales/*.ftl; do \
 				if [ "$$(basename "$$locale_file")" != "en-US.ftl" ]; then \
-					$(INSTALL) -m 644 "$$locale_file" "$(DESTDIR)$(DATAROOTDIR)/locales/$$prog/"; \
+					$(INSTALL) -v -m 644 "$$locale_file" "$(DESTDIR)$(LOCALEDIR)/$$prog/"; \
 				fi; \
 			done; \
 		fi; \
 	done
+
 else
 locales:
 install-locales:
Index: coreutils/src/uucore/src/lib/mods/locale.rs
===================================================================
--- coreutils.orig/src/uucore/src/lib/mods/locale.rs
+++ coreutils/src/uucore/src/lib/mods/locale.rs
@@ -111,23 +111,33 @@ thread_local! {
     static LOCALIZER: OnceLock<Localizer> = const { OnceLock::new() };
 }
 
-/// Helper function to find the uucore locales directory from a utility's locales directory
+/// Helper function to find the uucore locales directory
 fn find_uucore_locales_dir(utility_locales_dir: &Path) -> Option<PathBuf> {
-    // Normalize the path to get absolute path
-    let normalized_dir = utility_locales_dir
-        .canonicalize()
-        .unwrap_or_else(|_| utility_locales_dir.to_path_buf());
-
-    // Walk up: locales -> printenv -> uu -> src
-    let uucore_locales = normalized_dir
-        .parent()? // printenv
-        .parent()? // uu
-        .parent()? // src
-        .join("uucore")
-        .join("locales");
+    #[cfg(debug_assertions)]
+    {
+        // During development, walk up from the utility's locales directory
+        let normalized_dir = utility_locales_dir
+            .canonicalize()
+            .unwrap_or_else(|_| utility_locales_dir.to_path_buf());
+
+        // Walk up: locales -> printenv -> uu -> src
+        let uucore_locales = normalized_dir
+            .parent()? // printenv
+            .parent()? // uu
+            .parent()? // src
+            .join("uucore")
+            .join("locales");
 
-    // Only return if the directory actually exists
-    uucore_locales.exists().then_some(uucore_locales)
+        // Only return if the directory actually exists
+        uucore_locales.exists().then_some(uucore_locales)
+    }
+
+    #[cfg(not(debug_assertions))]
+    {
+        let _ = utility_locales_dir;
+        let uucore_locales = PathBuf::from("/usr/share/coreutils/locales/uucore");
+        uucore_locales.exists().then_some(uucore_locales)
+    }
 }
 
 /// Create a bundle that combines common and utility-specific strings
@@ -426,25 +436,11 @@ pub fn setup_localization(p: &str) -> Re
 }
 
 #[cfg(not(debug_assertions))]
-fn resolve_locales_dir_from_exe_dir(exe_dir: &Path, p: &str) -> Option<PathBuf> {
-    // 1. <bindir>/locales/<prog>
-    let coreutils = exe_dir.join("locales").join(p);
-    if coreutils.exists() {
-        return Some(coreutils);
-    }
-
-    // 2. <prefix>/share/locales/<prog>
-    if let Some(prefix) = exe_dir.parent() {
-        let fhs = prefix.join("share").join("locales").join(p);
-        if fhs.exists() {
-            return Some(fhs);
-        }
-    }
-
-    // 3. <bindir>/<prog>   (legacy fall-back)
-    let fallback = exe_dir.join(p);
-    if fallback.exists() {
-        return Some(fallback);
+fn resolve_locales_dir(p: &str) -> Option<PathBuf> {
+    // Only look in /usr/share/coreutils/locales/<prog>
+    let locales_dir = PathBuf::from("/usr/share/coreutils/locales").join(p);
+    if locales_dir.exists() {
+        return Some(locales_dir);
     }
 
     None
@@ -481,23 +477,13 @@ fn get_locales_dir(p: &str) -> Result<Pa
 
     #[cfg(not(debug_assertions))]
     {
-        use std::env;
-        // In release builds, look relative to executable
-        let exe_path = env::current_exe().map_err(|e| {
-            LocalizationError::PathResolution(format!("Failed to get executable path: {e}"))
-        })?;
-
-        let exe_dir = exe_path.parent().ok_or_else(|| {
-            LocalizationError::PathResolution("Failed to get executable directory".to_string())
-        })?;
-
-        if let Some(dir) = resolve_locales_dir_from_exe_dir(exe_dir, p) {
+        // In release builds, only look in /usr/share/coreutils/locales/<prog>
+        if let Some(dir) = resolve_locales_dir(p) {
             return Ok(dir);
         }
 
         Err(LocalizationError::LocalesDirNotFound(format!(
-            "Release locales directory not found starting from {}",
-            exe_dir.quote()
+            "Locales directory not found at /usr/share/coreutils/locales/{p}"
         )))
     }
 }
@@ -1409,24 +1395,18 @@ invalid-syntax = This is { $missing
 #[cfg(all(test, not(debug_assertions)))]
 mod fhs_tests {
     use super::*;
-    use tempfile::TempDir;
 
     #[test]
-    fn resolves_fhs_share_locales_layout() {
-        // 1. Set up a fake installation prefix in a temp directory
-        let prefix = TempDir::new().unwrap(); // e.g.  /tmp/xyz
-        let bin_dir = prefix.path().join("bin"); //        /tmp/xyz/bin
-        let share_dir = prefix.path().join("share").join("locales").join("cut"); // /tmp/xyz/share/locales/cut
-        std::fs::create_dir_all(&share_dir).unwrap();
-        std::fs::create_dir_all(&bin_dir).unwrap();
-
-        // 2. Pretend the executable lives in <prefix>/bin
-        let exe_dir = bin_dir.as_path();
-
-        // 3. Ask the helper to resolve the locales dir
-        let result = resolve_locales_dir_from_exe_dir(exe_dir, "cut")
-            .expect("should find locales via FHS path");
-
-        assert_eq!(result, share_dir);
+    fn resolves_fixed_locales_path() {
+        // Test that resolve_locales_dir returns the expected fixed path
+        // This test only passes if /usr/share/coreutils/locales/<prog> exists on the system
+        let result = resolve_locales_dir("cut");
+        if let Some(dir) = result {
+            assert_eq!(
+                dir,
+                PathBuf::from("/usr/share/coreutils/locales/cut")
+            );
+        }
+        // If the directory doesn't exist, result is None which is expected
     }
 }