From 15d092f94a3abd4ba328a9c9ac4531320ec381ec Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Wed, 11 Jun 2014 11:28:03 +0200 Subject: install: allow options -D and -t to be used together * src/install.c (install_file_in_file_parents): Factor out the creation of any parent directories into ... (mkancesdirs_safe_wd): ... this new function. (install_file_in_dir): Add the parameter 'mkdir_and_install', and call the above new function if it evaluates to true. (main): During parsing of the -t option, move the check whether the target_directory exists down after the option parsing loop, and do not complain about stat(optarg,...) failing if -D was given. Pass 'mkdir_and_install' to install_file_in_dir(). * doc/coreutils.texi (install invocation): Remove the (false) restriction that -D would be ignored together with -t. Instead, clarify install's new bahavior. Fix the node's reference in the top-level @direntry for consistency. * src/install/basic-1.sh: Add tests for the now-allowed combination of the -D and -t options. * NEWS: Mention the improvement. --- tests/install/basic-1.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/install/basic-1.sh b/tests/install/basic-1.sh index 283426aca..9835d463e 100755 --- a/tests/install/basic-1.sh +++ b/tests/install/basic-1.sh @@ -112,4 +112,31 @@ ginstall: creating directory 'sub3/a/b/c' 'file' -> 'sub3/a/b/c/file' EOF +# Test -D together with -t (available since coreutils >= 8.23). +# Let ginstall create a completely new destination hierarchy. +ginstall -t sub4/a/b/c -Dv file >out 2>&1 || fail=1 +compare - out <<\EOF || fail=1 +ginstall: creating directory 'sub4' +ginstall: creating directory 'sub4/a' +ginstall: creating directory 'sub4/a/b' +ginstall: creating directory 'sub4/a/b/c' +'file' -> 'sub4/a/b/c/file' +EOF + +# Ensure that -D with an already existing file as -t's option argument fails. +touch sub4/file_exists || framework_failure_ +ginstall -t sub4/file_exists -Dv file >out 2>&1 && fail=1 +compare - out <<\EOF || fail=1 +ginstall: target 'sub4/file_exists' is not a directory +EOF + +# Ensure that -D with an already existing directory for -t's option argument +# succeeds. +mkdir sub4/dir_exists || framework_failure_ +touch sub4/dir_exists || framework_failure_ +ginstall -t sub4/dir_exists -Dv file >out 2>&1 || fail=1 +compare - out <<\EOF || fail=1 +'file' -> 'sub4/dir_exists/file' +EOF + Exit $fail -- cgit v1.2.3-70-g09d2