-#ifdef SUPPORT_HARD_LINKS
- char hlink1[MAXPATHLEN];
- char *hlink2;
- STRUCT_STAT st1, st2;
- int statret, ndx = master;
-
- if (link_stat(f_name_to(file, hlink1), &st1, 0) < 0)
- return;
- if (!(file->flags & FLAG_HLINK_TOL)) {
- while (!(file->flags & FLAG_HLINK_EOL)) {
- ndx = file->F_NEXT;
- file = FPTR(ndx);
+ STRUCT_STAT prev_st;
+ char namebuf[MAXPATHLEN], altbuf[MAXPATHLEN];
+ char *realname, *prev_name;
+ struct file_list *flist;
+ int gnum = inc_recurse ? F_HL_GNUM(file) : -1;
+ int prev_ndx = F_HL_PREV(file);
+
+ prev_name = realname = check_prior(prev_ndx, gnum, &flist);
+
+ if (!prev_name) {
+ struct file_struct *prev_file = flist->files[prev_ndx - flist->ndx_start];
+
+ /* Is the previous link is not complete yet? */
+ if (!(prev_file->flags & FLAG_HLINK_DONE)) {
+ /* Is the previous link being transferred? */
+ if (prev_file->flags & FLAG_FILE_SENT) {
+ /* Add ourselves to the list of files that will be
+ * updated when the transfer completes, and mark
+ * ourself as waiting for the transfer. */
+ F_HL_PREV(file) = F_HL_PREV(prev_file);
+ F_HL_PREV(prev_file) = ndx;
+ file->flags |= FLAG_FILE_SENT;
+ cur_flist->in_progress++;
+ return 1;
+ }
+ return 0;
+ }
+
+ /* There is a finished file to link with! */
+ if (!(prev_file->flags & FLAG_HLINK_FIRST)) {
+ /* The previous previous is FIRST when prev is not. */
+ prev_ndx = F_HL_PREV(prev_file);
+ prev_name = realname = check_prior(prev_ndx, gnum, &flist);
+ /* Update our previous pointer to point to the FIRST. */
+ F_HL_PREV(file) = prev_ndx;
+ }
+
+ if (!prev_name) {
+ int alt_dest;
+
+ prev_file = flist->files[prev_ndx - flist->ndx_start];
+ /* F_HL_PREV() is alt_dest value when DONE && FIRST. */
+ alt_dest = F_HL_PREV(prev_file);
+
+ if (alt_dest >= 0 && dry_run) {
+ pathjoin(namebuf, MAXPATHLEN, basis_dir[alt_dest],
+ f_name(prev_file, NULL));
+ prev_name = namebuf;
+ realname = f_name(prev_file, altbuf);
+ } else {
+ prev_name = f_name(prev_file, namebuf);
+ realname = prev_name;
+ }