]> Git Repo - buildroot-mgba.git/commitdiff
fs/common.mk: use find instead of shell glob patterns
authorMathieu Mirmont <[email protected]>
Thu, 10 Mar 2022 10:18:26 +0000 (11:18 +0100)
committerYann E. MORIN <[email protected]>
Sat, 12 Mar 2022 16:45:21 +0000 (17:45 +0100)
Different shells can have different behaviours when it comes to globbing
patterns. The dash shell (/bin/sh) on Debian testing switched to a
different fnmatch/glob implementation that results in this new behaviour:

Using bash:
    $ mkdir /tmp/foo
    $ echo /tmp/foo/.[^.]*
    /tmp/foo/.[^.]*

Using dash:
    $ mkdir /tmp/foo
    $ echo /tmp/foo/.[^.]*
    /tmp/foo/..

The current FAKEROOT script uses this shell glob pattern which now fails
on recent Debian testing systems:

    rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/run/..'
    rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/tmp/..'

Additionally, the glob will miss files which have at least two leading
dots, like ..foo ...bar or ......buz  (highly improbable, but still).

It seems safer to use `find | xargs rm` here instead of relying on shell
globbing patterns.

Signed-off-by: Mathieu Mirmont <[email protected]>
Signed-off-by: Yann E. MORIN <[email protected]>
fs/common.mk

index 45beb5ae7b7c71f657075e87359c1647e172c569..37eafac4f7a791a3648845e061943674d777d762 100644 (file)
@@ -186,7 +186,8 @@ $$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME): $$(ROOTFS_$(2)_DEPENDENCIES)
 
        $$(foreach hook,$$(ROOTFS_$(2)_PRE_GEN_HOOKS),\
                $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
-       echo "rm -rf $$(TARGET_DIR)/run/* $$(TARGET_DIR)/run/.[^.]* $$(TARGET_DIR)/tmp/* $$(TARGET_DIR)/tmp/.[^.]*" >> $$(FAKEROOT_SCRIPT)
+       echo "find $$(TARGET_DIR)/run/ -mindepth 1 -prune -print0 | xargs -0r rm -rf --" >> $$(FAKEROOT_SCRIPT)
+       echo "find $$(TARGET_DIR)/tmp/ -mindepth 1 -prune -print0 | xargs -0r rm -rf --" >> $$(FAKEROOT_SCRIPT)
        $$(call PRINTF,$$(ROOTFS_REPRODUCIBLE)) >> $$(FAKEROOT_SCRIPT)
        $$(call PRINTF,$$(ROOTFS_SELINUX)) >> $$(FAKEROOT_SCRIPT)
        $$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
This page took 0.03476 seconds and 4 git commands to generate.