From: Eric Blake Date: Fri, 10 Apr 2009 12:26:33 +0000 (-0600) Subject: Add undocumented _AS_CLEAN_DIR. X-Git-Tag: v2.64~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef8940d9b5a3fe2866027f82a535915da3e78829;p=thirdparty%2Fautoconf.git Add undocumented _AS_CLEAN_DIR. * lib/m4sugar/m4sh.m4 (_AS_CLEAN_DIR): New macro; fixes m4 quoting in previous patch. * lib/autotest/general.m4 (AT_INIT) : Use new macro. * tests/m4sh.at (_AS@&t@_CLEAN_DIR): New test. Reported by Ralf Wildenhues. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index be9ab9867..7ee10f36d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-04-10 Eric Blake + + Add undocumented _AS_CLEAN_DIR. + * lib/m4sugar/m4sh.m4 (_AS_CLEAN_DIR): New macro; fixes m4 quoting + in previous patch. + * lib/autotest/general.m4 (AT_INIT) : Use new + macro. + * tests/m4sh.at (_AS@&t@_CLEAN_DIR): New test. + Reported by Ralf Wildenhues. + 2009-04-09 Eric Blake Avoid problems caused by deleting in-use directory. diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4 index 9c6538e4e..906e481b1 100644 --- a/lib/autotest/general.m4 +++ b/lib/autotest/general.m4 @@ -1099,11 +1099,8 @@ at_fn_group_prepare () # under the shell's notion of the current directory. at_group_dir=$at_suite_dir/$at_group_normalized at_group_log=$at_group_dir/$as_me.log - if test -d "$at_group_dir"; then - find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \; - rm -fr "$at_group_dir"/* "$at_group_dir"/.[!.] "$at_group_dir"/.??* || + _AS_CLEAN_DIR("$at_group_dir") || AS_WARN([test directory for $at_group_normalized could not be cleaned.]) - fi # Be tolerant if the above `rm' was not able to remove the directory. AS_MKDIR_P(["$at_group_dir"]) diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index 88881b1f6..2b32802e9 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -1409,6 +1409,17 @@ m4_define([_AS_BOX_INDIR], _ASBOX]) +# _AS_CLEAN_DIR(DIR) +# ------------------ +# Remove all contents from within DIR, including any unwritable +# subdirectories, but leave DIR itself untouched. +m4_define([_AS_CLEAN_DIR], +[if test -d $1; then + find $1 -type d ! -perm -700 -exec chmod u+rwx {} \; + rm -fr $1/* $1/.[[!.]] $1/.??* +fi]) + + # AS_FUNCTION_DESCRIBE(NAME, [ARGS], DESCRIPTION, [WRAP-COLUMN = 79]) # ------------------------------------------------------------------- # Output a shell comment describing NAME and its arguments ARGS, then diff --git a/tests/m4sh.at b/tests/m4sh.at index def63aa9e..d747bfe95 100644 --- a/tests/m4sh.at +++ b/tests/m4sh.at @@ -1371,3 +1371,32 @@ AT_CHECK([cat log], [0], ]]) AT_CLEANUP + + +## --------------- ## +## _AS_CLEAN_DIR. ## +## --------------- ## + +AT_SETUP([_AS@&t@_CLEAN_DIR]) + +dnl ensure that we can erase all files in a directory. Note that +dnl _AS_CLEAN_DIR needs three globs to catch all these files. +AT_DATA_M4SH([script.as], [[dnl +AS_INIT +# Unwritable subdirectories are common during 'make distcheck'. +mkdir sub sub/unwritable || AS_ERROR([failed to mkdir]) +touch sub/unwritable/file || AS_ERROR([failed to touch]) +chmod a-wx sub/unwritable || AS_ERROR([failed to chmod]) +# Cygwin 1.5 can't touch 'sub/...', so make that file optional. +touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \ + || AS_ERROR([failed to touch]) +touch sub/... 2>/dev/null +_AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean]) +# rmdir instead of 'rm -fr' here proves that we emptied sub. +rmdir sub || AS_ERROR([failed to rmdir]) +]]) + +AT_CHECK_M4SH +AT_CHECK([./script]) + +AT_CLEANUP