diff mbox series

[v2] fs/common.mk: fix the globing pattern

Message ID 20220310120256.GA11974@parad0x.org
State Not Applicable
Headers show
Series [v2] fs/common.mk: fix the globing pattern | expand

Commit Message

Mathieu Mirmont March 10, 2022, 12:02 p.m. UTC
The FAKEROOT script uses [^x] wildcard patterns which, while supported
by many shells and interpreted like a regex, are undefined according
to POSIX.

The dash shell (/bin/sh) on Debian testing switched to a different
fnmatch/glob implementation that does not support [^x]. Instead it
treats [^x] as either "^" or "x", and as a result buildroot fails to
build on this distro:

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/..'

The correct form should be [!x] rather than [^x].

Signed-off-by: Mathieu Mirmont <mat@parad0x.org>
---
 fs/common.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yann E. MORIN March 12, 2022, 4:19 p.m. UTC | #1
Mathieu, All,

On 2022-03-10 13:02 +0100, Mathieu Mirmont via buildroot spake thusly:
> The FAKEROOT script uses [^x] wildcard patterns which, while supported
> by many shells and interpreted like a regex, are undefined according
> to POSIX.
> 
> The dash shell (/bin/sh) on Debian testing switched to a different
> fnmatch/glob implementation that does not support [^x]. Instead it
> treats [^x] as either "^" or "x", and as a result buildroot fails to
> build on this distro:
> 
> 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/..'
> 
> The correct form should be [!x] rather than [^x].
> 
> Signed-off-by: Mathieu Mirmont <mat@parad0x.org>
> ---
>  fs/common.mk | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/common.mk b/fs/common.mk
> index 45beb5ae7b..64a94d9ad8 100644
> --- a/fs/common.mk
> +++ b/fs/common.mk
> @@ -186,7 +186,7 @@ $$(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 "rm -rf $$(TARGET_DIR)/run/* $$(TARGET_DIR)/run/.[!.]* $$(TARGET_DIR)/tmp/* $$(TARGET_DIR)/tmp/.[!.]*" >> $$(FAKEROOT_SCRIPT)

I think I preferred your find-based solution, because, as far as I
understand, this is still broken, as it won't match files named, for
example "..foo"

The find-based solution, though, should work for everything and does not
risk any issue with badly interpreted blobs in varios shells and various
shell versions.

Regards,
Yann E. MORIN.

>  	$$(call PRINTF,$$(ROOTFS_REPRODUCIBLE)) >> $$(FAKEROOT_SCRIPT)
>  	$$(call PRINTF,$$(ROOTFS_SELINUX)) >> $$(FAKEROOT_SCRIPT)
>  	$$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
> -- 
> 2.35.1
> Changes v1 -> v2:
>   - Fix the regex rather than use find|xargs (suggested by Edgar Bonet & David Laight)
> 



> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
diff mbox series

Patch

diff --git a/fs/common.mk b/fs/common.mk
index 45beb5ae7b..64a94d9ad8 100644
--- a/fs/common.mk
+++ b/fs/common.mk
@@ -186,7 +186,7 @@  $$(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 "rm -rf $$(TARGET_DIR)/run/* $$(TARGET_DIR)/run/.[!.]* $$(TARGET_DIR)/tmp/* $$(TARGET_DIR)/tmp/.[!.]*" >> $$(FAKEROOT_SCRIPT)
 	$$(call PRINTF,$$(ROOTFS_REPRODUCIBLE)) >> $$(FAKEROOT_SCRIPT)
 	$$(call PRINTF,$$(ROOTFS_SELINUX)) >> $$(FAKEROOT_SCRIPT)
 	$$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)