From 4bf4433f70c911eb74f47f3f0af0b794b2e89ffb Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Fri, 17 Sep 2004 14:13:04 +0000 Subject: [PATCH] Missed a couple of MKDIR_P references in ltmain.in in my last patch; fix them carefully. Introduce an opt_dry_run to ltmain.in so that the implementations of func_mkdir_p can converge, and a func_mktempdir to do a better job of temporary directory creation: * libtoolize.in (func_mkdir_p): Don't fail if the directory wasn't created in dry run mode. * tests/defs (func_mkdir_p): Ditto. We don't actually have a dry run mode for the tests, but the function is written carefully to be kept in synch and work correctly here too. * config/ltmain.in (func_mkdir_p): Ditto. This copy of the function now only differs in its use of $echo over $ECHO. (func_extract_archive): Removed first redundant mkdir call. (func_mktempdir): New function that tries to avoid races when making temporary directories. (opt_dry_run): Set this if --dry-run is given at the CLI, or if tests/mdemo-dryrun.test has forced the value of $run. (func_mode_install): Call $MKDIR directly and error out if the directory cannot be created. (func_mode_link): Rather than copying func_mkdir_p into the wrapper script as a replacement for $MKDIR_P, we know that the script won't be called my `make -j', so write the current value of $MKDIR. --- ChangeLog | 26 +++++++++++++++++ config/ltmain.in | 74 ++++++++++++++++++++++++++++++++---------------- libtoolize.in | 10 +++---- tests/defs | 10 +++---- 4 files changed, 86 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index b943db74b..4392bb835 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2004-09-17 Gary V. Vaughan + + Missed a couple of MKDIR_P references in ltmain.in in my last + patch; fix them carefully. Introduce an opt_dry_run to ltmain.in + so that the implementations of func_mkdir_p can converge, and a + func_mktempdir to do a better job of temporary directory creation: + + * libtoolize.in (func_mkdir_p): Don't fail if the directory wasn't + created in dry run mode. + * tests/defs (func_mkdir_p): Ditto. We don't actually have a dry + run mode for the tests, but the function is written carefully to + be kept in synch and work correctly here too. + * config/ltmain.in (func_mkdir_p): Ditto. This copy of the + function now only differs in its use of $echo over $ECHO. + (func_extract_archive): Removed first redundant mkdir call. + (func_mktempdir): New function that tries to avoid races when + making temporary directories. + (opt_dry_run): Set this if --dry-run is given at the CLI, or if + tests/mdemo-dryrun.test has forced the value of $run. + (func_mode_install): Call $MKDIR directly and error out if the + directory cannot be created. + (func_mode_link): Rather than copying func_mkdir_p into the + wrapper script as a replacement for $MKDIR_P, we know that the + script won't be called my `make -j', so write the current value of + $MKDIR. + 2004-09-17 Peter O'Gorman * m4/libtool.m4: remove an extra "]" diff --git a/config/ltmain.in b/config/ltmain.in index 5109b192a..9f679ac4d 100644 --- a/config/ltmain.in +++ b/config/ltmain.in @@ -193,8 +193,9 @@ execute_dlfiles= lo2o="s/\\.lo\$/.${objext}/" o2lo="s/\\.${objext}\$/.lo/" -opt_help=false +opt_dry_run=${run-false} ## inherit $run when mdemo-dryrun.test sets it above opt_duplicate_deps=false +opt_help=false # If this variable is set in any of the actions, the command in it # will be execed at the end. This prevents here-documents from being @@ -618,11 +619,15 @@ Otherwise, only FILE itself is deleted using RM." set -x ;; - --dlopen) test "$#" -eq 0 && func_missing_arg "$opt" && break + -dlopen) test "$#" -eq 0 && func_missing_arg "$opt" && break execute_dlfiles="$execute_dlfiles $1" + shift + ;; + + --dry-run | -n) opt_dry_run=: + run=: ;; - --dry-run | -n) run=: ;; --features) func_features ;; --finish) mode="finish" ;; @@ -663,7 +668,7 @@ Otherwise, only FILE itself is deleted using RM." ;; # Separate optargs to long options: - --dlopen=*|--mode=*|--tag=*) + -dlopen=*|--mode=*|--tag=*) arg=`echo "$opt" | $SED "$my_sed_long_arg"` opt=`echo "$opt" | $SED "$my_sed_long_opt"` set -- "$opt" "$arg" ${1+"$@"} @@ -721,7 +726,7 @@ func_mkdir_p () my_directory_path="$1" my_dir_list= - if test -n "$my_directory_path"; then + if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then # Protect directory names starting with `-' case $my_directory_path in @@ -751,11 +756,45 @@ func_mkdir_p () $MKDIR "$my_dir" 2>/dev/null || : done IFS="$save_mkdir_p_IFS" + + # Bail out if we (or some other process) failed to create a directory. + test -d "$my_directory_path" || \ + func_fatal_error "Failed to create \`$1'" + fi +} + + +# func_mktempdir +# Make a temporary directory that won't clash with other running +# libtool processes, and avoids race conditions if possible +func_mktempdir () +{ + my_template="${TMPDIR-/tmp}/libtool" + + if test "$opt_dry_run" = ":"; then + # Return a directory name, but don't create it in dry-run mode + my_tmpdir="${my_template}-$$" + else + + # If mktemp works, use that first and foremost + my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null` + + if test ! -d "$my_tmpdir"; then + # Failing that, at least try and use $RANDOM to avoid a race + my_tmpdir="${my_template}-${RANDOM-0}$$" + + save_mktempdir_umask=`umask` + umask 0077 + $MKDIR "$my_tmpdir" + umask $save_mktempdir_umask + fi + + # If we're not in dry-run mode, bomb out on failure + test -d "$my_tmpdir" || \ + func_fatal_error "cannot create temporary directory \`$my_tmpdir'" fi - # Bail out if we (or some other process) failed to create a directory. - test -d "$my_directory_path" || \ - func_fatal_error "Failed to create \`$1'" + echo "$my_tmpdir" } @@ -1113,8 +1152,6 @@ func_extract_archives () { my_xabs="" my_xdir="" - func_mkdir_p "$my_gentop" - for my_xlib in $my_oldlibs; do # Extract the objects. case $my_xlib in @@ -1152,7 +1189,7 @@ func_extract_archives () { $RM "${darwin_base_archive}" cd "$darwin_curdir" done # $darwin_arches - ## Okay now we have a bunch of thin objects, gotta fatten them up :) + ## Okay now we've a bunch of thin objects, gotta fatten them up :) darwin_filelist=`find unfat-$$ -type f | xargs basename | sort -u | $NL2SP` darwin_file= darwin_files= @@ -2187,18 +2224,7 @@ func_mode_install () outputname= if test "$fast_install" = no && test -n "$relink_command"; then if test "$finalize" = yes && test -z "$run"; then - tmpdir="/tmp" - test -n "$TMPDIR" && tmpdir="$TMPDIR" - tmpdir="$tmpdir/libtool-$$" - save_umask=`umask` - umask 0077 - if $MKDIR_P "$tmpdir"; then - umask $save_umask - else - umask $save_umask - func_error "error: cannot create temporary directory \`$tmpdir'" - continue - fi + func_mktempdir "${TMPDIR-/tmp}/libtool-XXXXXXXX" file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'` outputname="$tmpdir/$file" # Replace the output file specification. @@ -6215,7 +6241,7 @@ else file=\"\$\$-\$program\" if test ! -d \"\$progdir\"; then - $MKDIR_P \"\$progdir\" + $MKDIR \"\$progdir\" else $RM \"\$progdir/\$file\" fi" diff --git a/libtoolize.in b/libtoolize.in index 9087bd3b6..b1e467d75 100644 --- a/libtoolize.in +++ b/libtoolize.in @@ -315,7 +315,7 @@ func_mkdir_p () my_directory_path="$1" my_dir_list= - if test -n "$my_directory_path"; then + if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then # Protect directory names starting with `-' case $my_directory_path in @@ -345,11 +345,11 @@ func_mkdir_p () $MKDIR "$my_dir" 2>/dev/null || : done IFS="$save_mkdir_p_IFS" - fi - # Bail out if we (or some other process) failed to create a directory. - test -d "$my_directory_path" || \ - func_fatal_error "Failed to create \`$1'" + # Bail out if we (or some other process) failed to create a directory. + test -d "$my_directory_path" || \ + func_fatal_error "Failed to create \`$1'" + fi } diff --git a/tests/defs b/tests/defs index d219480f2..9d183fa6a 100644 --- a/tests/defs +++ b/tests/defs @@ -191,7 +191,7 @@ func_mkdir_p () my_directory_path="$1" my_dir_list= - if test -n "$my_directory_path"; then + if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then # Protect directory names starting with `-' case $my_directory_path in @@ -221,11 +221,11 @@ func_mkdir_p () $MKDIR "$my_dir" 2>/dev/null || : done IFS="$save_mkdir_p_IFS" - fi - # Bail out if we (or some other process) failed to create a directory. - test -d "$my_directory_path" || \ - func_fatal_error "Failed to create \`$1'" + # Bail out if we (or some other process) failed to create a directory. + test -d "$my_directory_path" || \ + func_fatal_error "Failed to create \`$1'" + fi } # func_mkprefixdir -- 2.47.2