+2009-04-10 Eric Blake <ebb9@byu.net>
+
+ 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) <at_fn_group_prepare>: Use new
+ macro.
+ * tests/m4sh.at (_AS@&t@_CLEAN_DIR): New test.
+ Reported by Ralf Wildenhues.
+
2009-04-09 Eric Blake <ebb9@byu.net>
Avoid problems caused by deleting in-use directory.
# 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"])
_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
]])
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