purge-locales: Handle empty locale directories better
authorTrent Piepho <tpiepho@kymetacorp.com>
Tue, 8 Mar 2016 21:02:15 +0000 (21:02 +0000)
committerPeter Korsgaard <peter@korsgaard.com>
Thu, 28 Apr 2016 21:48:09 +0000 (23:48 +0200)
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.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Makefile

index 0e4beb2d3b06b4db1a280938d5b0dbd16fbd2b69..daa32a41d808cdfd792a8141f8ac30a2d7d82131 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -583,7 +583,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 ]; \