autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: autotest vs. in-use directories


From: Eric Blake
Subject: Re: autotest vs. in-use directories
Date: Fri, 10 Apr 2009 06:29:50 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Ralf Wildenhues on 4/10/2009 12:02 AM:
>> No, the point of the above change is that I'm NOT deleting the current 
>> directory.  Rather, I'm using ALL THREE globs to collectively name every 
>> possible file within the directory (think 'a', '...', and '.a', each of 
>> which 
>> only match one of the three globs),
> 
> But adding a test case that proves that all
> three globs are necessary would be prudent.

Yep, particularly since I botched the m4 quoting for the .[!.] glob.  As
penance, I factored this into a new m4sh macro.  I'm committing this
(which leaves it undocumented); if we like it, then we can go one step
further by removing the leading _ and documenting it.  Or even decide to
fold in the subsequent AS_MKDIR_P step, to guarantee a clean dir whether
or not it previously existed as a directory, but failing if it existed as
a file.  [side note: Cygwin 1.5 can't touch '...' without a managed mount,
but cygwin 1.7 removed that restriction.]

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknfO74ACgkQ84KuGfSFAYBEtACfSXwyoCDe1/WMfmZg9/iXAyXz
xjAAn1jpUjoACN0Wyht9r3wmKma7LS8m
=5c6y
-----END PGP SIGNATURE-----
>From ef8940d9b5a3fe2866027f82a535915da3e78829 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Fri, 10 Apr 2009 06:26:33 -0600
Subject: [PATCH] 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@&address@hidden): New test.
Reported by Ralf Wildenhues.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog               |   10 ++++++++++
 lib/autotest/general.m4 |    5 +----
 lib/m4sugar/m4sh.m4     |   11 +++++++++++
 tests/m4sh.at           |   29 +++++++++++++++++++++++++++++
 4 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index be9ab98..7ee10f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-04-10  Eric Blake  <address@hidden>
+
+       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@&address@hidden): New test.
+       Reported by Ralf Wildenhues.
+
 2009-04-09  Eric Blake  <address@hidden>

        Avoid problems caused by deleting in-use directory.
diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index 9c6538e..906e481 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 88881b1..2b32802 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 def63aa..d747bfe 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@&address@hidden)
+
+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
-- 
1.6.1.2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]