]> git.cworth.org Git - tar/blobdiff - src/create.c
Preserve hard links with --remove-files
[tar] / src / create.c
index a925160e1be90c5b5b0cab7cc301a3ec3e7135fc..559aaa08b9fc1e55046c1b01a7d403b9a4a59bb8 100644 (file)
@@ -744,7 +744,7 @@ write_header_name (struct tar_stat_info *st)
       return write_short_name (st);
     }
   else if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
-          < strlen (st->file_name))
+          <= strlen (st->file_name))
     return write_long_name (st);
   else
     return write_short_name (st);
@@ -1377,7 +1377,7 @@ static Hash_table *link_table;
 static bool
 dump_hard_link (struct tar_stat_info *st)
 {
-  if (link_table && st->stat.st_nlink > 1)
+  if (link_table && (st->stat.st_nlink > 1 || remove_files_option))
     {
       struct link lp;
       struct link *duplicate;
@@ -1398,7 +1398,7 @@ dump_hard_link (struct tar_stat_info *st)
          block_ordinal = current_block_ordinal ();
          assign_string (&st->link_name, link_name);
          if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
-             < strlen (link_name))
+             <= strlen (link_name))
            write_long_link (st);
 
          st->stat.st_size = 0;
@@ -1424,7 +1424,7 @@ file_count_links (struct tar_stat_info *st)
 {
   if (hard_dereference_option)
     return;
-  if (st->stat.st_nlink > 1)
+  if (st->stat.st_nlink > 1 || remove_files_option)
     {
       struct link *duplicate;
       struct link *lp = xmalloc (offsetof (struct link, name)