From 1209e0ebff2cdfbff2195a162d85df5de349bbaf Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 10 Dec 2014 04:34:02 +0200 Subject: [PATCH] Fix tar -c -l file file When the same file is added several times to the archive, count correctly the number of hard links. See also 37ddfb0b. * src/create.c (dump_hard_link): Don't decrease nlink if it is 0. * tests/link04.at: Test -cl options. --- src/create.c | 4 ++-- tests/link04.at | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/create.c b/src/create.c index 0d1a5ff..1b08e0b 100644 --- a/src/create.c +++ b/src/create.c @@ -1472,8 +1472,8 @@ dump_hard_link (struct tar_stat_info *st) /* We found a link. */ char const *link_name = safer_name_suffix (duplicate->name, true, absolute_names_option); - - duplicate->nlink--; + if (duplicate->nlink) + duplicate->nlink--; block_ordinal = current_block_ordinal (); assign_string (&st->link_name, link_name); diff --git a/tests/link04.at b/tests/link04.at index 03697bd..53ca31c 100644 --- a/tests/link04.at +++ b/tests/link04.at @@ -39,6 +39,10 @@ tar tvf archive | sed ' s,.*[[0-9]] dir/,dir/, ' | sort +echo -- + +tar cfl archive dir dir + echo == tar chf archive dir @@ -55,6 +59,7 @@ dir/file dir/file link to dir/file dir/symlink -> file dir/symlink link to dir/symlink +-- == dir/ dir/FOO -- 2.43.0