Skip to contentSkip to conversation

purge-locales: Handle empty locale directories better

PATCH Superseded Trent Piepho 3 participants 4 messages Mar 4, 2016 – Apr 28, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 purge-locales: Handle empty locale directories better

If a locale directory is empty, shell code like "for langdir in $$dir/*;" will loop once with langdir set to "path/to/dir/*", rather than not looping at all, which would obviously be the desired behavior.

Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?) that transform the expression from "${langdir##*/}" to "*" to "list of all files in buildroot root dir". Which is most certainly not what this command was supposed to do.

If one of those files happens to be an 8GB flash image, grep consumes all available memory and crashes trying to search it.

---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile +2 -1
index f2822a2..0df5a35 100644
@@ -581,7 +581,8 @@ define PURGE_LOCALES
 	do \
 		for langdir in $$dir/*; \
 		do \
-			grep -qx $${langdir##*/} $(LOCALE_WHITELIST) || rm -rf $$langdir; \
+			[ -e "$${langdir}" ] || continue; \
+			grep -qx "$${langdir##*/}" $(LOCALE_WHITELIST) || rm -rf $$langdir; \
 		done; \
 	done
 	if [ -d $(TARGET_DIR)/usr/share/X11/locale ]; \
Signature · 1 line
2.7.0.25.gfc10eb5.dirty
#1 lore raw

PATCH 1/1 purge-locales: Handle empty locale directories better

Quoted 5 lines · Trent Piepho

If a locale directory is empty, shell code like "for langdir in $$dir/*;" will loop once with langdir set to "path/to/dir/*", rather than not looping at all, which would obviously be the desired behavior.

Quoted 7 lines

Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?) that transform the expression from "${langdir##*/}" to "*" to "list of all files in buildroot root dir". Which is most certainly not what this command was supposed to do.

If one of those files happens to be an 8GB flash image, grep consumes all available memory and crashes trying to search it.

Good catch!

Quoted 11 lines
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile +0 -0
index f2822a2..0df5a35 100644

Makefile define PURGE_LOCALES · line 584

Quoted 5 lines
Makefile +1 -1
@@ -581,7 +581,8 @@ define PURGE_LOCALES
 	do \
 		for langdir in $$dir/*; \
 		do \
-			grep -qx $${langdir##*/} $(LOCALE_WHITELIST) || rm -rf $$langdir; \
+			[ -e "$${langdir}" ] || continue; \

I would prefer a more explicit if, the continue is a bit more difficult to grok.

Regards,
Arnout

Quoted 5 lines
Makefile +1 -0
+			grep -qx "$${langdir##*/}" $(LOCALE_WHITELIST) || rm -rf $$langdir; \
 		done; \
 	done
 	if [ -d $(TARGET_DIR)/usr/share/X11/locale ]; \
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#2 lore raw

PATCH v2 1/1 purge-locales: Handle empty locale directories better

If a locale directory is empty, shell code like "for langdir in $$dir/*;" will loop once with langdir set to "path/to/dir/*", rather than not looping at all, which would obviously be the desired behavior.

Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?) that transform the expression from "${langdir##*/}" to "*" to "list of all files in buildroot root dir". Which is most certainly not what this command was supposed to do.

If one of those files happens to be an 8GB flash image, grep consumes all available memory and crashes trying to search it.

---
 Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Makefile +4 -1
index f2822a2..44ded9d 100644
@@ -581,7 +581,10 @@ define PURGE_LOCALES
 	do \
 		for langdir in $$dir/*; \
 		do \
-			grep -qx $${langdir##*/} $(LOCALE_WHITELIST) || rm -rf $$langdir; \
+			if [ -e "$${langdir}" ]; \
+			then \
+				grep -qx "$${langdir##*/}" $(LOCALE_WHITELIST) || rm -rf $$langdir; \
+			fi \
 		done; \
 	done
 	if [ -d $(TARGET_DIR)/usr/share/X11/locale ]; \
Signature · 1 line
2.7.0.25.gfc10eb5.dirty
#3 lore raw

PATCH v2 1/1 purge-locales: Handle empty locale directories better

Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Trent" == Trent Piepho <[email protected]> writes:

If a locale directory is empty, shell code like "for langdir in $$dir/*;" will loop once with langdir set to "path/to/dir/*", rather than not looping at all, which would obviously be the desired behavior.

Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?) that transform the expression from "${langdir##*/}" to "*" to "list of all files in buildroot root dir". Which is most certainly not what this command was supposed to do.

Quoted 4 lines

If one of those files happens to be an 8GB flash image, grep consumes all available memory and crashes trying to search it.

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard