-#ifdef SUPPORT_HARD_LINKS
- if (!hlink_list || !file->link_u.links)
- return 0;
- if (skip && !(file->flags & FLAG_HLINK_EOL))
- hlink_list[file->F_HLINDEX] = file->F_NEXT;
- if (hlink_list[file->F_HLINDEX] != ndx) {
- if (verbose > 2) {
- rprintf(FINFO, "\"%s\" is a hard link\n",
- safe_fname(f_name(file)));
+ int32 from, prev;
+ struct file_struct *file, *file_next;
+ struct ht_int32_node *node = NULL;
+ int32 gnum, gnum_next;
+
+ qsort(ndx_list, ndx_count, sizeof ndx_list[0],
+ (int (*)()) hlink_compare_gnum);
+
+ for (from = 0; from < ndx_count; from++) {
+ file = hlink_flist->sorted[ndx_list[from]];
+ gnum = F_HL_GNUM(file);
+ if (inc_recurse) {
+ node = hashtable_find(prior_hlinks, gnum, 1);
+ if (!node->data) {
+ node->data = new_array0(char, 5);
+ assert(gnum >= hlink_flist->ndx_start);
+ file->flags |= FLAG_HLINK_FIRST;
+ prev = -1;
+ } else if (CVAL(node->data, 0) == 0) {
+ struct file_list *flist;
+ struct file_struct *fp;
+ prev = IVAL(node->data, 1);
+ flist = flist_for_ndx(prev);
+ assert(flist != NULL);
+ fp = flist->files[prev - flist->ndx_start];
+ fp->flags &= ~FLAG_HLINK_LAST;
+ } else
+ prev = -1;
+ } else {
+ file->flags |= FLAG_HLINK_FIRST;
+ prev = -1;
+ }
+ for ( ; from < ndx_count-1; file = file_next, gnum = gnum_next, from++) { /*SHARED ITERATOR*/
+ file_next = hlink_flist->sorted[ndx_list[from+1]];
+ gnum_next = F_HL_GNUM(file_next);
+ if (gnum != gnum_next)
+ break;
+ F_HL_PREV(file) = prev;
+ /* The linked list uses over-the-wire ndx values. */
+ if (unsort_ndx)
+ prev = F_NDX(file);
+ else
+ prev = ndx_list[from] + hlink_flist->ndx_start;
+ }
+ if (prev < 0 && !inc_recurse) {
+ /* Disable hard-link bit and set DONE so that
+ * HLINK_BUMP()-dependent values are unaffected. */
+ file->flags &= ~(FLAG_HLINKED | FLAG_HLINK_FIRST);
+ file->flags |= FLAG_HLINK_DONE;
+ continue;
+ }
+
+ file->flags |= FLAG_HLINK_LAST;
+ F_HL_PREV(file) = prev;
+ if (inc_recurse && CVAL(node->data, 0) == 0) {
+ if (unsort_ndx)
+ prev = F_NDX(file);
+ else
+ prev = ndx_list[from] + hlink_flist->ndx_start;
+ SIVAL(node->data, 1, prev);