-#ifdef SUPPORT_HARD_LINKS
- int head;
- if (skip && !(file->flags & FLAG_HLINK_EOL))
- head = hlink_list[file->F_HLINDEX] = file->F_NEXT;
- else
- head = hlink_list[file->F_HLINDEX];
- if (ndx != head) {
- struct file_struct *head_file = FPTR(head);
- if (!log_format_has_i && verbose > 1)
- rprintf(FINFO, "\"%s\" is a hard link\n", f_name(file));
- if (head_file->F_HLINDEX == FINISHED_LINK) {
- STRUCT_STAT st2, st3;
- char *toname = f_name(head_file);
- if (link_stat(toname, &st2, 0) < 0) {
- rsyserr(FERROR, errno, "stat %s failed",
- full_fname(toname));
- return -1;
- }
- if (statret < 0 && basis_dir[0] != NULL) {
- char cmpbuf[MAXPATHLEN];
- int j = 0;
- do {
- pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
- if (link_stat(cmpbuf, &st3, 0) < 0)
- continue;
- if (link_dest) {
- if (st2.st_dev != st3.st_dev
- || st2.st_ino != st3.st_ino)
- continue;
- statret = 1;
- st = &st3;
- if (verbose < 2 || !log_format_has_i)
- itemizing = code = 0;
- break;
- }
- if (!unchanged_file(cmpbuf, file, &st3))
- continue;
- statret = 1;
- st = &st3;
- if (unchanged_attrs(file, &st3))
- break;
- } while (basis_dir[++j] != NULL);
+ STRUCT_STAT prev_st;
+ char prev_name[MAXPATHLEN], altbuf[MAXPATHLEN], *realname;
+ int alt_dest, prev_ndx = F_HL_PREV(file);
+ struct file_struct *prev_file = FPTR(prev_ndx);
+
+ /* 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_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_SENT;
+ return 1;
+ }
+ return 0;
+ }
+
+ /* There is a finished file to link with! */
+ if (!(prev_file->flags & FLAG_HLINK_FIRST)) {
+ /* The previous previous will be marked with FIRST. */
+ prev_ndx = F_HL_PREV(prev_file);
+ prev_file = FPTR(prev_ndx);
+ /* Update our previous pointer to point to the first. */
+ F_HL_PREV(file) = prev_ndx;
+ }
+ alt_dest = F_HL_PREV(prev_file); /* alternate value when DONE && FIRST */
+ if (alt_dest >= 0 && dry_run) {
+ pathjoin(prev_name, MAXPATHLEN, basis_dir[alt_dest],
+ f_name(prev_file, NULL));
+ f_name(prev_file, altbuf);
+ realname = altbuf;
+ } else {
+ f_name(prev_file, prev_name);
+ realname = prev_name;
+ }
+
+ if (link_stat(prev_name, &prev_st, 0) < 0) {
+ rsyserr(FERROR, errno, "stat %s failed",
+ full_fname(prev_name));
+ return -1;
+ }
+
+ if (statret < 0 && basis_dir[0] != NULL) {
+ /* If we match an alt-dest item, we don't output this as a change. */
+ char cmpbuf[MAXPATHLEN];
+ STRUCT_STAT alt_st;
+ int j = 0;
+ do {
+ pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
+ if (link_stat(cmpbuf, &alt_st, 0) < 0)
+ continue;
+ if (link_dest) {
+ if (prev_st.st_dev != alt_st.st_dev
+ || prev_st.st_ino != alt_st.st_ino)
+ continue;
+ statret = 1;
+ *stp = alt_st;
+ if (verbose < 2 || !stdout_format_has_i) {
+ itemizing = 0;
+ code = FNONE;
+ if (verbose > 1 && maybe_ATTRS_REPORT)
+ rprintf(FCLIENT, "%s is uptodate\n", fname);
+ }
+ break;