From 80e9070c77718b7ff0e913182e54842754726ce8 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sat, 19 Nov 2011 01:29:05 +0000 Subject: Improve the way we call "rm" in the build system; fixes trac #4916 We avoid calling "rm -rf" with no file arguments; this fixes cleaning on Solaris, where that fails. We also check for suspicious arguments: anything containing "..", starting "/", or containing a "*" (you need to call $(wildcard ...) yourself now if you really want globbing). This should make things a little safer. --- mk/tree.mk | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'mk/tree.mk') diff --git a/mk/tree.mk b/mk/tree.mk index 2010c362f3..564e55353c 100644 --- a/mk/tree.mk +++ b/mk/tree.mk @@ -74,3 +74,24 @@ RM_OPTS = -f RM_OPTS_REC = -rf endif +# If $1 is empty then we don't do anything (as "rm -rf" fails on +# Solaris; trac #4916). +# If $1 contains a * then we fail; globbing needs to be done at the call +# site using $(wildcard ...). This makes it a little safer, as it's +# harder to accidentally delete something you didn't mean to. +# Similarly, we fail if any argument contains ".." or starts with a "/". + +removeFiles = $(call removeHelper,removeFiles,"$(RM)",$(RM_OPTS),$1) +removeTrees = $(call removeHelper,removeTrees,"$(RM)",$(RM_OPTS_REC),$1) + +removeHelper = $(if $(strip $4),\ + $(if $(findstring *,$4),\ + $(error $1: Got a star: $4),\ + $(if $(findstring ..,$4),\ + $(error $1: Got dot-dot: $4),\ + $(if $(filter /%,$4),\ + $(error $1: Got leading slash: $4),\ + $2 $3 $4\ + )))\ + ) + -- cgit v1.2.1