What can I say, the following patch works for me - and passes the simple test I'm including.
Mind you, I didn't do any research to find out how to disable the test on platforms like win32 where hard links are *supposed* to fail. diff -urN tar-1.15.1/src/extract.c tar-1.15.1/src/extract.c --- tar-1.15.1/src/extract.c +++ tar-1.15.1/src/extract.c @@ -923,6 +923,25 @@ struct stat st1, st2; int e; + if (strip_name_components) + { + size_t prefix_len = stripped_prefix_len (link_name, + strip_name_components); + if (prefix_len == (size_t) -1) + { + WARN ((0, 0, + _("%s: Cannot hard link to `%s':" + " not extracted due to `--strip-components=%d'"), + quotearg_colon (file_name), link_name, + strip_name_components)); + skip_member (); + if (backup_option) + undo_last_backup (); + break; + } + link_name += prefix_len; + } + /* MSDOS does not implement links. However, djgpp's link() actually copies the file. */ status = link (link_name, file_name); diff -urN tar-1.15.1.tests/testsuite.at tar-1.15.1.tests/testsuite.at --- tar-1.15.1/tests/testsuite.at +++ tar-1.15.1/tests/testsuite.at @@ -77,6 +77,7 @@ m4_include([extrac03.at]) m4_include([extrac04.at]) m4_include([extrac05.at]) +m4_include([extrac06.at]) m4_include([gzip.at]) diff -urN tar-1.15.1/tests/extrac06.at tar-1.15.1/tests/extrac06.at --- tar-1.15.1/tests/extrac06.at +++ tar-1.15.1/tests/extrac06.at @@ -0,0 +1,26 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# +# Test suite for GNU tar. +# Written by Peter Samuelson, who abandons this file to the public domain. +# +# Test extraction of hard links with a --strip-components flag. + +AT_SETUP([extracting hard links]) +AT_KEYWORDS([extract06]) + +AT_TAR_CHECK([ +mkdir blim blim/tibbek +genfile --length 315 > blim/tibbek/garl +ln blim/tibbek/garl blim/angofh +tar cf archive blim || exit 1 +rm -r blim +tar xvf archive --strip-components=1 | sort +], +[0], +[blim/ +blim/angofh +blim/tibbek/ +blim/tibbek/garl +]) + +AT_CLEANUP
signature.asc
Description: Digital signature