Fixed a failing hunk.
[rsync/rsync-patches.git] / acls.diff
index 7e832a2..720fae5 100644 (file)
--- a/acls.diff
+++ b/acls.diff
@@ -811,7 +811,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +              if (type == SMB_ACL_TYPE_ACCESS)
 +                      F_ACL(file) = ndx;
 +              else
-+                      F_DEFACL(file) = ndx;
++                      F_DEF_ACL(file) = ndx;
 +              racl_list = &default_acl_list;
 +      } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
 +}
@@ -845,7 +845,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +              if (type == SMB_ACL_TYPE_ACCESS)
 +                      F_ACL(file) = ndx;
 +              else
-+                      F_DEFACL(file) = ndx;
++                      F_DEF_ACL(file) = ndx;
 +              racl = sxp->def_acl;
 +              racl_list = &default_acl_list;
 +      } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
@@ -921,7 +921,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
 +      /* Ensure that chmod() will be called to restore any lost setid bits. */
 +      if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
-+       && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
++       && BITS_EQUAL(old_mode, mode, CHMOD_BITS))
 +              old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
 +#endif
 +
@@ -965,7 +965,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +                      eq = sxp->acc_acl
 +                          && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
 +              } else {
-+                      ndx = F_DEFACL(file);
++                      ndx = F_DEF_ACL(file);
 +                      if (ndx < 0 || (size_t)ndx >= default_acl_list.count)
 +                              continue;
 +                      duo_item = default_acl_list.items;
@@ -1138,7 +1138,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  extern int preserve_devices;
  extern int preserve_specials;
  extern int preserve_links;
-@@ -95,7 +96,8 @@ path
+@@ -93,7 +94,8 @@ path
  ****************************************************************************/
  static int make_bak_dir(char *fullpath)
  {
@@ -1148,7 +1148,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        char *rel = fullpath + backup_dir_len;
        char *end = rel + strlen(rel);
        char *p = end;
-@@ -127,15 +129,24 @@ static int make_bak_dir(char *fullpath)
+@@ -125,15 +127,24 @@ static int make_bak_dir(char *fullpath)
                if (p >= rel) {
                        /* Try to transfer the directory settings of the
                         * actual dir that the files are coming from. */
@@ -1177,7 +1177,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                        }
                }
                *p = '/';
-@@ -173,15 +184,18 @@ static int robust_move(const char *src, 
+@@ -171,15 +182,18 @@ static int robust_move(const char *src, 
   * We will move the file to be deleted into a parallel directory tree. */
  static int keep_backup(const char *fname)
  {
@@ -1198,7 +1198,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  
        if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
                return 1; /* the file could have disappeared */
-@@ -191,6 +205,13 @@ static int keep_backup(const char *fname
+@@ -189,6 +203,13 @@ static int keep_backup(const char *fname
                return 0;
        }
  
@@ -1212,7 +1212,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        /* Check to see if this is a device file, or link */
        if ((am_root && preserve_devices && IS_DEVICE(file->mode))
         || (preserve_specials && IS_SPECIAL(file->mode))) {
-@@ -261,7 +282,7 @@ static int keep_backup(const char *fname
+@@ -260,7 +281,7 @@ static int keep_backup(const char *fname
                if (robust_move(fname, buf) != 0) {
                        rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
                                full_fname(fname), buf);
@@ -1324,16 +1324,16 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  extern int preserve_links;
  extern int preserve_hard_links;
  extern int preserve_devices;
-@@ -143,6 +144,8 @@ static void list_file_entry(struct file_
+@@ -147,6 +148,8 @@ static void list_file_entry(struct file_
        permstring(permbuf, f->mode);
+       len = F_LENGTH(f);
  
 +      /* TODO: indicate '+' if the entry has an ACL. */
 +
  #ifdef SUPPORT_LINKS
        if (preserve_links && S_ISLNK(f->mode)) {
                rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
-@@ -621,6 +624,12 @@ static struct file_struct *recv_file_ent
+@@ -624,6 +627,12 @@ static struct file_struct *recv_file_ent
        }
  #endif
  
@@ -1343,10 +1343,10 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +              extra_len += (S_ISDIR(mode) ? 2 : 1) * sizeof (union flist_extras);
 +#endif
 +
-       sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
+       if (always_checksum && S_ISREG(mode))
+               extra_len += SUM_EXTRA_CNT * EXTRA_LEN;
  
-       alloc_len = file_struct_len + dirname_len + basename_len
-@@ -725,6 +734,11 @@ static struct file_struct *recv_file_ent
+@@ -736,6 +745,11 @@ static struct file_struct *recv_file_ent
                read_buf(f, bp, checksum_len);
        }
  
@@ -1358,16 +1358,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        return file;
  }
  
-@@ -969,6 +983,8 @@ void unmake_file(struct file_struct *fil
- {
-       union flist_extras *start = (union flist_extras *)file
-                                 - (flist_extra_ndx - 1);
-+      if (preserve_acls && S_ISDIR(file->mode))
-+              start--;
-       free(start);
- }
-@@ -977,6 +993,9 @@ static struct file_struct *send_file_nam
+@@ -996,6 +1010,9 @@ static struct file_struct *send_file_nam
                                          unsigned short flags)
  {
        struct file_struct *file;
@@ -1377,7 +1368,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  
        file = make_file(fname, flist, stp, flags,
                         f == -2 ? SERVER_FILTERS : ALL_FILTERS);
-@@ -986,11 +1005,24 @@ static struct file_struct *send_file_nam
+@@ -1005,11 +1022,24 @@ static struct file_struct *send_file_nam
        if (chmod_modes && !S_ISLNK(file->mode))
                file->mode = tweak_mode(file->mode, chmod_modes);
  
@@ -1412,24 +1403,23 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  extern int preserve_links;
  extern int preserve_devices;
  extern int preserve_specials;
-@@ -89,6 +90,7 @@ extern int one_file_system;
- extern int file_struct_len;
+@@ -87,6 +88,7 @@ extern int force_delete;
+ extern int one_file_system;
  extern struct stats stats;
  extern dev_t filesystem_dev;
 +extern mode_t orig_umask;
  extern char *backup_dir;
  extern char *backup_suffix;
  extern int backup_suffix_len;
-@@ -447,22 +449,27 @@ static void do_delete_pass(struct file_l
+@@ -518,21 +520,26 @@ static void do_delete_pass(struct file_l
                rprintf(FINFO, "                    \r");
  }
  
 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
 +int unchanged_attrs(struct file_struct *file, statx *sxp)
  {
-       if (preserve_perms
--       && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
-+       && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
+-      if (preserve_perms && !BITS_EQUAL(st->st_mode, file->mode, CHMOD_BITS))
++      if (preserve_perms && !BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS))
                return 0;
  
 -      if (am_root && preserve_uid && st->st_uid != F_UID(file))
@@ -1453,12 +1443,12 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
             int32 iflags, uchar fnamecmp_type, const char *xname)
  {
        if (statret >= 0) { /* A from-dest-dir statret can == 1! */
-@@ -470,20 +477,24 @@ void itemize(struct file_struct *file, i
+@@ -540,20 +547,24 @@ void itemize(struct file_struct *file, i
                    : S_ISDIR(file->mode) ? !omit_dir_times
                    : !S_ISLNK(file->mode);
  
--              if (S_ISREG(file->mode) && file->length != st->st_size)
-+              if (S_ISREG(file->mode) && file->length != sxp->st.st_size)
+-              if (S_ISREG(file->mode) && F_LENGTH(file) != st->st_size)
++              if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size)
                        iflags |= ITEM_REPORT_SIZE;
                if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
                  && !(iflags & ITEM_MATCHED)
@@ -1466,8 +1456,8 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 -               || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
 +               || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
                        iflags |= ITEM_REPORT_TIME;
--              if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
-+              if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS))
+-              if (!BITS_EQUAL(st->st_mode, file->mode, CHMOD_BITS))
++              if (!BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS))
                        iflags |= ITEM_REPORT_PERMS;
 -              if (preserve_uid && am_root && F_UID(file) != st->st_uid)
 +              if (preserve_uid && am_root && F_UID(file) != sxp->st.st_uid)
@@ -1483,16 +1473,16 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        } else
                iflags |= ITEM_IS_NEW;
  
-@@ -735,7 +746,7 @@ void check_for_finished_hlinks(int itemi
+@@ -808,7 +819,7 @@ void check_for_finished_hlinks(int itemi
   * handling the file, -1 if no dest-linking occurred, or a non-negative
   * value if we found an alternate basis file. */
  static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
 -                       char *cmpbuf, STRUCT_STAT *stp, int itemizing,
 +                       char *cmpbuf, statx *sxp, int itemizing,
-                        int maybe_ATTRS_REPORT, enum logcode code)
+                        enum logcode code)
  {
        int best_match = -1;
-@@ -744,7 +755,7 @@ static int try_dests_reg(struct file_str
+@@ -817,7 +828,7 @@ static int try_dests_reg(struct file_str
  
        do {
                pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
@@ -1501,7 +1491,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                        continue;
                switch (match_level) {
                case 0:
-@@ -752,16 +763,20 @@ static int try_dests_reg(struct file_str
+@@ -825,16 +836,20 @@ static int try_dests_reg(struct file_str
                        match_level = 1;
                        /* FALL THROUGH */
                case 1:
@@ -1525,7 +1515,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                                continue;
                        best_match = j;
                        match_level = 3;
-@@ -776,7 +791,7 @@ static int try_dests_reg(struct file_str
+@@ -849,7 +864,7 @@ static int try_dests_reg(struct file_str
        if (j != best_match) {
                j = best_match;
                pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
@@ -1534,16 +1524,22 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                        return -1;
        }
  
-@@ -784,15 +799,20 @@ static int try_dests_reg(struct file_str
- #ifdef SUPPORT_HARD_LINKS
-               if (link_dest) {
-                       int i = itemizing && (verbose > 1 || stdout_format_has_i > 1);
--                      if (hard_link_one(file, ndx, fname, 0, stp,
-+                      if (hard_link_one(file, ndx, fname, 0, sxp,
-                                         cmpbuf, 1, i, code) < 0)
+@@ -859,16 +874,25 @@ static int try_dests_reg(struct file_str
+                       if (!hard_link_one(file, fname, cmpbuf, 1))
                                goto try_a_copy;
-                       if (preserve_hard_links && IS_HLINKED(file))
-                               hard_link_cluster(file, ndx, itemizing, code, j);
+                       if (preserve_hard_links && F_IS_HLINKED(file))
+-                              finish_hard_link(file, fname, stp, itemizing, code, j);
++                              finish_hard_link(file, fname, &sxp->st, itemizing, code, j);
+                       if (itemizing && (verbose > 1 || stdout_format_has_i > 1)) {
+-                              itemize(file, ndx, 1, stp,
++#ifdef SUPPORT_ACLS
++                              if (preserve_acls && !ACL_READY(*sxp))
++                                      get_acl(fname, sxp);
++#endif
++                              itemize(file, ndx, 1, sxp,
+                                       ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
+                                       0, "");
+                       }
                } else
  #endif
 -              if (itemizing)
@@ -1555,10 +1551,10 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +#endif
 +                      itemize(file, ndx, 0, sxp, 0, 0, NULL);
 +              }
-               if (verbose > 1 && maybe_ATTRS_REPORT) {
+               if (verbose > 1 && maybe_ATTRS_REPORT)
                        rprintf(FCLIENT, "%s is uptodate\n", fname);
-               }
-@@ -808,8 +828,13 @@ static int try_dests_reg(struct file_str
+               return -2;
+@@ -885,8 +909,13 @@ static int try_dests_reg(struct file_str
                        }
                        return -1;
                }
@@ -1574,16 +1570,25 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                set_file_attrs(fname, file, NULL, 0);
                if (maybe_ATTRS_REPORT
                 && ((!itemizing && verbose && match_level == 2)
-@@ -830,7 +855,7 @@ static int try_dests_reg(struct file_str
+@@ -897,7 +926,7 @@ static int try_dests_reg(struct file_str
+               }
+ #ifdef SUPPORT_HARD_LINKS
+               if (preserve_hard_links && F_IS_HLINKED(file))
+-                      finish_hard_link(file, fname, stp, itemizing, code, -1);
++                      finish_hard_link(file, fname, &sxp->st, itemizing, code, -1);
+ #endif
+               return -2;
+       }
+@@ -909,7 +938,7 @@ static int try_dests_reg(struct file_str
   * handling the file, or -1 if no dest-linking occurred, or a non-negative
   * value if we found an alternate basis file. */
  static int try_dests_non(struct file_struct *file, char *fname, int ndx,
 -                       char *cmpbuf, STRUCT_STAT *stp, int itemizing,
 +                       char *cmpbuf, statx *sxp, int itemizing,
-                        int maybe_ATTRS_REPORT, enum logcode code)
+                        enum logcode code)
  {
        char lnk[MAXPATHLEN];
-@@ -862,24 +887,24 @@ static int try_dests_non(struct file_str
+@@ -942,24 +971,24 @@ static int try_dests_non(struct file_str
  
        do {
                pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
@@ -1613,16 +1618,16 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                                continue;
                        break;
  #endif
-@@ -893,7 +918,7 @@ static int try_dests_non(struct file_str
-                       break;
+@@ -974,7 +1003,7 @@ static int try_dests_non(struct file_str
                case TYPE_SPECIAL:
                case TYPE_DEVICE:
--                      if (stp->st_rdev != MAKEDEV(F_DMAJOR(file), F_DMINOR(file)))
-+                      if (sxp->st.st_rdev != MAKEDEV(F_DMAJOR(file), F_DMINOR(file)))
+                       devp = F_RDEV_P(file);
+-                      if (stp->st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)))
++                      if (sxp->st.st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)))
                                continue;
                        break;
  #ifdef SUPPORT_LINKS
-@@ -910,7 +935,11 @@ static int try_dests_non(struct file_str
+@@ -991,7 +1020,11 @@ static int try_dests_non(struct file_str
                        match_level = 2;
                        best_match = j;
                }
@@ -1635,7 +1640,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                        match_level = 3;
                        best_match = j;
                        break;
-@@ -923,7 +952,7 @@ static int try_dests_non(struct file_str
+@@ -1004,7 +1037,7 @@ static int try_dests_non(struct file_str
        if (j != best_match) {
                j = best_match;
                pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
@@ -1644,7 +1649,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                        return -1;
        }
  
-@@ -954,7 +983,15 @@ static int try_dests_non(struct file_str
+@@ -1035,7 +1068,15 @@ static int try_dests_non(struct file_str
                            : ITEM_LOCAL_CHANGE
                             + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0);
                        char *lp = match_level == 3 ? "" : NULL;
@@ -1661,7 +1666,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                }
                if (verbose > 1 && maybe_ATTRS_REPORT) {
                        rprintf(FCLIENT, "%s%s is uptodate\n",
-@@ -967,6 +1004,7 @@ static int try_dests_non(struct file_str
+@@ -1048,6 +1089,7 @@ static int try_dests_non(struct file_str
  }
  
  static int phase = 0;
@@ -1669,7 +1674,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  
  /* Acts on the_file_list->file's ndx'th item, whose name is fname.  If a dir,
   * make sure it exists, and has the right permissions/timestamp info.  For
-@@ -988,7 +1026,8 @@ static void recv_generator(char *fname, 
+@@ -1068,7 +1110,8 @@ static void recv_generator(char *fname, 
        static int need_fuzzy_dirlist = 0;
        struct file_struct *fuzzy_file = NULL;
        int fd = -1, f_copy = -1;
@@ -1679,7 +1684,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        struct file_struct *back_file = NULL;
        int statret, real_ret, stat_errno;
        char *fnamecmp, *partialptr, *backupptr = NULL;
-@@ -1044,6 +1083,9 @@ static void recv_generator(char *fname, 
+@@ -1124,6 +1167,9 @@ static void recv_generator(char *fname, 
                } else if (!dry_run)
                        return;
        }
@@ -1689,7 +1694,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        if (dry_run > 1) {
                statret = -1;
                stat_errno = ENOENT;
-@@ -1051,7 +1093,7 @@ static void recv_generator(char *fname, 
+@@ -1131,7 +1177,7 @@ static void recv_generator(char *fname, 
                const char *dn = file->dirname ? file->dirname : ".";
                if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
                        if (relative_paths && !implied_dirs
@@ -1698,7 +1703,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                         && create_directory_path(fname) < 0) {
                                rsyserr(FERROR, errno,
                                        "recv_generator: mkdir %s failed",
-@@ -1063,6 +1105,10 @@ static void recv_generator(char *fname, 
+@@ -1143,6 +1189,10 @@ static void recv_generator(char *fname, 
                        }
                        if (fuzzy_basis)
                                need_fuzzy_dirlist = 1;
@@ -1709,7 +1714,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                }
                parent_dirname = dn;
  
-@@ -1072,7 +1118,7 @@ static void recv_generator(char *fname, 
+@@ -1152,7 +1202,7 @@ static void recv_generator(char *fname, 
                        need_fuzzy_dirlist = 0;
                }
  
@@ -1718,7 +1723,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                                    keep_dirlinks && S_ISDIR(file->mode));
                stat_errno = errno;
        }
-@@ -1090,8 +1136,9 @@ static void recv_generator(char *fname, 
+@@ -1170,8 +1220,9 @@ static void recv_generator(char *fname, 
         * mode based on the local permissions and some heuristics. */
        if (!preserve_perms) {
                int exists = statret == 0
@@ -1730,7 +1735,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        }
  
        if (S_ISDIR(file->mode)) {
-@@ -1100,8 +1147,8 @@ static void recv_generator(char *fname, 
+@@ -1180,8 +1231,8 @@ static void recv_generator(char *fname, 
                 * file of that name and it is *not* a directory, then
                 * we need to delete it.  If it doesn't exist, then
                 * (perhaps recursively) create it. */
@@ -1741,7 +1746,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                                return;
                        statret = -1;
                }
-@@ -1110,14 +1157,14 @@ static void recv_generator(char *fname, 
+@@ -1190,14 +1241,14 @@ static void recv_generator(char *fname, 
                        dry_run++;
                }
                real_ret = statret;
@@ -1755,10 +1760,10 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                if (statret != 0 && basis_dir[0] != NULL) {
 -                      int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
 +                      int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
-                                             itemizing, maybe_ATTRS_REPORT, code);
+                                             itemizing, code);
                        if (j == -2) {
                                itemizing = 0;
-@@ -1126,7 +1173,11 @@ static void recv_generator(char *fname, 
+@@ -1206,7 +1257,11 @@ static void recv_generator(char *fname, 
                                statret = 1;
                }
                if (itemizing && f_out != -1) {
@@ -1771,7 +1776,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                                statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
                }
                if (real_ret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
-@@ -1146,21 +1197,21 @@ static void recv_generator(char *fname, 
+@@ -1226,21 +1281,21 @@ static void recv_generator(char *fname, 
                                return;
                        }
                }
@@ -1790,16 +1795,16 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +              goto cleanup;
        }
  
-       if (preserve_hard_links && IS_HLINKED(file)
--          && hard_link_check(file, ndx, fname, statret, &st,
-+          && hard_link_check(file, ndx, fname, statret, &sx,
-                              itemizing, code, HL_CHECK_MASTER))
+ #ifdef SUPPORT_HARD_LINKS
+       if (preserve_hard_links && F_HLINK_NOT_FIRST(file)
+-       && hard_link_check(file, ndx, fname, statret, &st, itemizing, code))
 -              return;
++       && hard_link_check(file, ndx, fname, statret, &sx, itemizing, code))
 +              goto cleanup;
+ #endif
  
        if (preserve_links && S_ISLNK(file->mode)) {
- #ifdef SUPPORT_LINKS
-@@ -1179,14 +1230,14 @@ static void recv_generator(char *fname, 
+@@ -1260,17 +1315,17 @@ static void recv_generator(char *fname, 
                        char lnk[MAXPATHLEN];
                        int len;
  
@@ -1814,10 +1819,14 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 -                              set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
 +                                      itemize(file, ndx, 0, &sx, 0, 0, NULL);
 +                              set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
-                               if (preserve_hard_links && IS_HLINKED(file))
-                                       hard_link_cluster(file, ndx, itemizing, code, -1);
+ #ifdef SUPPORT_HARD_LINKS
+                               if (preserve_hard_links && F_IS_HLINKED(file))
+-                                      finish_hard_link(file, fname, &st, itemizing, code, -1);
++                                      finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
+ #endif
                                if (remove_source_files == 1)
-@@ -1195,10 +1246,10 @@ static void recv_generator(char *fname, 
+                                       goto return_with_success;
+@@ -1278,10 +1333,10 @@ static void recv_generator(char *fname, 
                        }
                        /* Not the right symlink (or not a symlink), so
                         * delete it. */
@@ -1827,19 +1836,10 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                } else if (basis_dir[0] != NULL) {
 -                      int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
 +                      int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
-                                             itemizing, maybe_ATTRS_REPORT, code);
+                                             itemizing, code);
                        if (j == -2) {
  #ifndef CAN_HARDLINK_SYMLINK
-@@ -1214,7 +1265,7 @@ static void recv_generator(char *fname, 
-                               statret = 1;
-               }
-               if (preserve_hard_links && IS_HLINKED(file)
--                  && hard_link_check(file, ndx, fname, -1, &st,
-+                  && hard_link_check(file, ndx, fname, -1, &sx,
-                                      itemizing, code, HL_SKIP))
-                       return;
-               if (do_symlink(sl, fname) != 0) {
-@@ -1223,7 +1274,7 @@ static void recv_generator(char *fname, 
+@@ -1306,7 +1361,7 @@ static void recv_generator(char *fname, 
                } else {
                        set_file_attrs(fname, file, NULL, 0);
                        if (itemizing) {
@@ -1848,7 +1848,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                                        ITEM_LOCAL_CHANGE, 0, NULL);
                        }
                        if (code != FNONE && verbose)
-@@ -1246,31 +1297,36 @@ static void recv_generator(char *fname, 
+@@ -1332,33 +1387,38 @@ static void recv_generator(char *fname, 
                if (statret == 0) {
                        char *t;
                        if (IS_DEVICE(file->mode)) {
@@ -1863,9 +1863,9 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                                t = "special file";
                        }
                        if (statret == 0
--                       && (st.st_mode & ~CHMOD_BITS) == (file->mode & ~CHMOD_BITS)
+-                       && BITS_EQUAL(st.st_mode, file->mode, _S_IFMT)
 -                       && st.st_rdev == rdev) {
-+                       && (sx.st.st_mode & ~CHMOD_BITS) == (file->mode & ~CHMOD_BITS)
++                       && BITS_EQUAL(sx.st.st_mode, file->mode, _S_IFMT)
 +                       && sx.st.st_rdev == rdev) {
                                /* The device or special file is identical. */
 -                              if (itemizing)
@@ -1879,8 +1879,11 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +                                      itemize(file, ndx, 0, &sx, 0, 0, NULL);
 +                              }
 +                              set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
-                               if (preserve_hard_links && IS_HLINKED(file))
-                                       hard_link_cluster(file, ndx, itemizing, code, -1);
+ #ifdef SUPPORT_HARD_LINKS
+                               if (preserve_hard_links && F_IS_HLINKED(file))
+-                                      finish_hard_link(file, fname, &st, itemizing, code, -1);
++                                      finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
+ #endif
                                if (remove_source_files == 1)
                                        goto return_with_success;
 -                              return;
@@ -1892,19 +1895,10 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                } else if (basis_dir[0] != NULL) {
 -                      int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
 +                      int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
-                                             itemizing, maybe_ATTRS_REPORT, code);
+                                             itemizing, code);
                        if (j == -2) {
  #ifndef CAN_HARDLINK_SPECIAL
-@@ -1286,7 +1342,7 @@ static void recv_generator(char *fname, 
-                               statret = 1;
-               }
-               if (preserve_hard_links && IS_HLINKED(file)
--                  && hard_link_check(file, ndx, fname, -1, &st,
-+                  && hard_link_check(file, ndx, fname, -1, &sx,
-                                      itemizing, code, HL_SKIP))
-                       return;
-               if (verbose > 2) {
-@@ -1299,7 +1355,11 @@ static void recv_generator(char *fname, 
+@@ -1388,7 +1448,11 @@ static void recv_generator(char *fname, 
                } else {
                        set_file_attrs(fname, file, NULL, 0);
                        if (itemizing) {
@@ -1917,7 +1911,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                                        ITEM_LOCAL_CHANGE, 0, NULL);
                        }
                        if (code != FNONE && verbose)
-@@ -1309,7 +1369,7 @@ static void recv_generator(char *fname, 
+@@ -1400,7 +1464,7 @@ static void recv_generator(char *fname, 
                        if (remove_source_files == 1)
                                goto return_with_success;
                }
@@ -1926,7 +1920,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        }
  
        if (!S_ISREG(file->mode)) {
-@@ -1343,7 +1403,7 @@ static void recv_generator(char *fname, 
+@@ -1434,7 +1498,7 @@ static void recv_generator(char *fname, 
        }
  
        if (update_only && statret == 0
@@ -1935,7 +1929,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                if (verbose > 1)
                        rprintf(FINFO, "%s is newer\n", fname);
                return;
-@@ -1352,20 +1412,20 @@ static void recv_generator(char *fname, 
+@@ -1443,20 +1507,20 @@ static void recv_generator(char *fname, 
        fnamecmp = fname;
        fnamecmp_type = FNAMECMP_FNAME;
  
@@ -1951,7 +1945,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        if (statret != 0 && basis_dir[0] != NULL) {
 -              int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
 +              int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
-                                     itemizing, maybe_ATTRS_REPORT, code);
+                                     itemizing, code);
                if (j == -2) {
                        if (remove_source_files == 1)
                                goto return_with_success;
@@ -1960,7 +1954,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                }
                if (j >= 0) {
                        fnamecmp = fnamecmpbuf;
-@@ -1375,7 +1435,7 @@ static void recv_generator(char *fname, 
+@@ -1466,7 +1530,7 @@ static void recv_generator(char *fname, 
        }
  
        real_ret = statret;
@@ -1969,30 +1963,21 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  
        if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
            && link_stat(partialptr, &partial_st, 0) == 0
-@@ -1394,7 +1454,7 @@ static void recv_generator(char *fname, 
+@@ -1485,7 +1549,7 @@ static void recv_generator(char *fname, 
                                rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
                                        fname, fnamecmpbuf);
                        }
--                      st.st_size = fuzzy_file->length;
-+                      sx.st.st_size = fuzzy_file->length;
+-                      st.st_size = F_LENGTH(fuzzy_file);
++                      sx.st.st_size = F_LENGTH(fuzzy_file);
                        statret = 0;
                        fnamecmp = fnamecmpbuf;
                        fnamecmp_type = FNAMECMP_FUZZY;
-@@ -1403,7 +1463,7 @@ static void recv_generator(char *fname, 
-       if (statret != 0) {
-               if (preserve_hard_links && IS_HLINKED(file)
--                  && hard_link_check(file, ndx, fname, statret, &st,
-+                  && hard_link_check(file, ndx, fname, statret, &sx,
-                                      itemizing, code, HL_SKIP))
-                       return;
-               if (stat_errno == ENOENT)
-@@ -1413,36 +1473,49 @@ static void recv_generator(char *fname, 
+@@ -1504,36 +1568,41 @@ static void recv_generator(char *fname, 
                return;
        }
  
--      if (append_mode && st.st_size > file->length)
-+      if (append_mode && sx.st.st_size > file->length)
+-      if (append_mode && st.st_size > F_LENGTH(file))
++      if (append_mode && sx.st.st_size > F_LENGTH(file))
                return;
  
        if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
@@ -2005,28 +1990,22 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                        do_unlink(partialptr);
                        handle_partial_dir(partialptr, PDIR_DELETE);
                }
-               if (itemizing) {
--                      itemize(file, ndx, real_ret, &real_st,
-+#ifdef SUPPORT_ACLS
-+                      if (preserve_acls && real_ret == 0)
-+                              get_acl(fnamecmp, &real_sx);
-+#endif
-+                      itemize(file, ndx, real_ret, &real_sx,
-                               0, 0, NULL);
+-              if (itemizing)
+-                      itemize(file, ndx, statret, &st, 0, 0, NULL);
+-              set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
++              if (itemizing) {
 +#ifdef SUPPORT_ACLS
-+                      if (preserve_acls) {
-+                              if (fnamecmp_type == FNAMECMP_FNAME) {
-+                                      sx.acc_acl = real_sx.acc_acl;
-+                                      sx.def_acl = real_sx.def_acl;
-+                              } else
-+                                      free_acl(&real_sx);
-+                      }
++                      if (preserve_acls && statret == 0)
++                              get_acl(fnamecmp, &sx);
 +#endif
-               }
--              set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
++                      itemize(file, ndx, statret, &sx, 0, 0, NULL);
++              }
 +              set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
-               if (preserve_hard_links && IS_HLINKED(file))
-                       hard_link_cluster(file, ndx, itemizing, code, -1);
+ #ifdef SUPPORT_HARD_LINKS
+               if (preserve_hard_links && F_IS_HLINKED(file))
+-                      finish_hard_link(file, fname, &st, itemizing, code, -1);
++                      finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
+ #endif
                if (remove_source_files != 1)
 -                      return;
 +                      goto cleanup;
@@ -2044,15 +2023,13 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                fnamecmp = partialptr;
                fnamecmp_type = FNAMECMP_PARTIAL_DIR;
                statret = 0;
-@@ -1466,17 +1539,21 @@ static void recv_generator(char *fname, 
-         pretend_missing:
+@@ -1558,16 +1627,20 @@ static void recv_generator(char *fname, 
                /* pretend the file didn't exist */
-               if (preserve_hard_links && IS_HLINKED(file)
--                  && hard_link_check(file, ndx, fname, statret, &st,
-+                  && hard_link_check(file, ndx, fname, statret, &sx,
-                                      itemizing, code, HL_SKIP))
+ #ifdef SUPPORT_HARD_LINKS
+               if (preserve_hard_links && F_HLINK_NOT_LAST(file))
 -                      return;
 +                      goto cleanup;
+ #endif
                statret = real_ret = -1;
 +#ifdef SUPPORT_ACLS
 +              if (preserve_acls && ACL_READY(sx))
@@ -2069,7 +2046,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                }
                if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
                        close(fd);
-@@ -1487,7 +1564,7 @@ static void recv_generator(char *fname, 
+@@ -1578,7 +1651,7 @@ static void recv_generator(char *fname, 
                                full_fname(backupptr));
                        unmake_file(back_file);
                        close(fd);
@@ -2078,7 +2055,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                }
                if ((f_copy = do_open(backupptr,
                    O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
-@@ -1495,14 +1572,14 @@ static void recv_generator(char *fname, 
+@@ -1586,14 +1659,14 @@ static void recv_generator(char *fname, 
                                full_fname(backupptr));
                        unmake_file(back_file);
                        close(fd);
@@ -2095,7 +2072,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        }
  
        if (verbose > 2)
-@@ -1520,24 +1597,32 @@ static void recv_generator(char *fname, 
+@@ -1615,26 +1688,34 @@ static void recv_generator(char *fname, 
                        iflags |= ITEM_BASIS_TYPE_FOLLOWS;
                if (fnamecmp_type == FNAMECMP_FUZZY)
                        iflags |= ITEM_XNAME_FOLLOWS;
@@ -2105,7 +2082,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +                      get_acl(fnamecmp, &real_sx);
 +#endif
 +              itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
-                       fuzzy_file ? fuzzy_file->basename : NULL);
+                       fuzzy_file ? F_BASENAME(fuzzy_file) : NULL);
 +#ifdef SUPPORT_ACLS
 +              if (preserve_acls)
 +                      free_acl(&real_sx);
@@ -2113,8 +2090,11 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        }
  
        if (!do_xfers) {
-               if (preserve_hard_links && IS_HLINKED(file))
-                       hard_link_cluster(file, ndx, itemizing, code, -1);
+ #ifdef SUPPORT_HARD_LINKS
+               if (preserve_hard_links && F_IS_HLINKED(file))
+-                      finish_hard_link(file, fname, &st, itemizing, code, -1);
++                      finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
+ #endif
 -              return;
 +              goto cleanup;
        }
@@ -2133,7 +2113,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  
        if (f_copy >= 0) {
                close(f_copy);
-@@ -1550,6 +1635,13 @@ static void recv_generator(char *fname, 
+@@ -1647,6 +1728,13 @@ static void recv_generator(char *fname, 
        }
  
        close(fd);
@@ -2147,7 +2127,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  }
  
  void generate_files(int f_out, struct file_list *flist, char *local_name)
-@@ -1611,6 +1703,8 @@ void generate_files(int f_out, struct fi
+@@ -1713,6 +1801,8 @@ void generate_files(int f_out, struct fi
         * notice that and let us know via the redo pipe (or its closing). */
        ignore_timeout = 1;
  
@@ -2164,24 +2144,24 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  extern int link_dest;
 +extern int preserve_acls;
  extern int make_backups;
- extern int flist_extra_ndx;
  extern int remove_source_files;
-@@ -155,15 +156,19 @@ void init_hard_links(void)
+ extern int stdout_format_has_i;
+@@ -119,15 +120,19 @@ void match_hard_links(void)
+ }
  
- #ifdef SUPPORT_HARD_LINKS
  static int maybe_hard_link(struct file_struct *file, int ndx,
--                         char *fname, int statret, STRUCT_STAT *st,
-+                         char *fname, int statret, statx *sxp,
-                          char *toname, STRUCT_STAT *to_st,
-                          int itemizing, enum logcode code)
+-                         const char *fname, int statret, STRUCT_STAT *stp,
++                         const char *fname, int statret, statx *sxp,
+                          const char *oldname, STRUCT_STAT *old_stp,
+                          const char *realname, int itemizing, enum logcode code)
  {
        if (statret == 0) {
--              if (st->st_dev == to_st->st_dev
--               && st->st_ino == to_st->st_ino) {
-+              if (sxp->st.st_dev == to_st->st_dev
-+               && sxp->st.st_ino == to_st->st_ino) {
+-              if (stp->st_dev == old_stp->st_dev
+-               && stp->st_ino == old_stp->st_ino) {
++              if (sxp->st.st_dev == old_stp->st_dev
++               && sxp->st.st_ino == old_stp->st_ino) {
                        if (itemizing) {
--                              itemize(file, ndx, statret, st,
+-                              itemize(file, ndx, statret, stp,
 +#ifdef SUPPORT_ACLS
 +                              if (preserve_acls && !ACL_READY(*sxp))
 +                                      get_acl(fname, sxp);
@@ -2190,108 +2170,133 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                                        ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
                                        0, "");
                        }
-@@ -178,13 +183,13 @@ static int maybe_hard_link(struct file_s
-                       return -1;
-               }
-       }
--      return hard_link_one(file, ndx, fname, statret, st, toname,
-+      return hard_link_one(file, ndx, fname, statret, sxp, toname,
-                            0, itemizing, code);
- }
- #endif
+@@ -148,7 +153,11 @@ static int maybe_hard_link(struct file_s
  
- int hard_link_check(struct file_struct *file, int ndx, char *fname,
--                  int statret, STRUCT_STAT *st, int itemizing,
+       if (hard_link_one(file, fname, oldname, 0)) {
+               if (itemizing) {
+-                      itemize(file, ndx, statret, stp,
++#ifdef SUPPORT_ACLS
++                      if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
++                              get_acl(fname, sxp);
++#endif
++                      itemize(file, ndx, statret, sxp,
+                               ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
+                               realname);
+               }
+@@ -162,7 +171,7 @@ static int maybe_hard_link(struct file_s
+ /* Only called if FLAG_HLINKED is set and FLAG_HLINK_FIRST is not.  Returns:
+  * 0 = process the file, 1 = skip the file, -1 = error occurred. */
+ int hard_link_check(struct file_struct *file, int ndx, const char *fname,
+-                  int statret, STRUCT_STAT *stp, int itemizing,
 +                  int statret, statx *sxp, int itemizing,
-                   enum logcode code, int skip)
+                   enum logcode code)
  {
- #ifdef SUPPORT_HARD_LINKS
-@@ -228,7 +233,7 @@ int hard_link_check(struct file_struct *
-                                                || st2.st_ino != st3.st_ino)
-                                                       continue;
-                                               statret = 1;
--                                              st = &st3;
-+                                              sxp->st = st3;
-                                               if (verbose < 2 || !stdout_format_has_i) {
-                                                       itemizing = 0;
-                                                       code = FNONE;
-@@ -238,12 +243,16 @@ int hard_link_check(struct file_struct *
-                                       if (!unchanged_file(cmpbuf, file, &st3))
-                                               continue;
-                                       statret = 1;
--                                      st = &st3;
--                                      if (unchanged_attrs(file, &st3))
-+                                      sxp->st = st3;
+       STRUCT_STAT prev_st;
+@@ -213,18 +222,20 @@ int hard_link_check(struct file_struct *
+       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;
++              statx alt_sx;
+               int j = 0;
 +#ifdef SUPPORT_ACLS
-+                                      if (preserve_acls)
-+                                              get_acl(cmpbuf, sxp);
++              alt_sx.acc_acl = alt_sx.def_acl = NULL;
 +#endif
-+                                      if (unchanged_attrs(file, sxp))
-                                               break;
-                               } while (basis_dir[++j] != NULL);
+               do {
+                       pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
+-                      if (link_stat(cmpbuf, &alt_st, 0) < 0)
++                      if (link_stat(cmpbuf, &alt_sx.st, 0) < 0)
+                               continue;
+                       if (link_dest) {
+-                              if (prev_st.st_dev != alt_st.st_dev
+-                               || prev_st.st_ino != alt_st.st_ino)
++                              if (prev_st.st_dev != alt_sx.st.st_dev
++                               || prev_st.st_ino != alt_sx.st.st_ino)
+                                       continue;
+                               statret = 1;
+-                              *stp = alt_st;
+                               if (verbose < 2 || !stdout_format_has_i) {
+                                       itemizing = 0;
+                                       code = FNONE;
+@@ -233,16 +244,36 @@ int hard_link_check(struct file_struct *
+                               }
+                               break;
                        }
--                      maybe_hard_link(file, ndx, fname, statret, st,
-+                      maybe_hard_link(file, ndx, fname, statret, sxp,
-                                       toname, &st2, itemizing, code);
-                       if (remove_source_files == 1 && do_xfers)
-                               send_msg_int(MSG_SUCCESS, ndx);
-@@ -258,7 +267,7 @@ int hard_link_check(struct file_struct *
- #ifdef SUPPORT_HARD_LINKS
- int hard_link_one(struct file_struct *file, int ndx, char *fname,
--                int statret, STRUCT_STAT *st, char *toname, int terse,
-+                int statret, statx *sxp, char *toname, int terse,
-                 int itemizing, enum logcode code)
- {
-       if (do_link(toname, fname)) {
-@@ -274,7 +283,11 @@ int hard_link_one(struct file_struct *fi
-       }
-       if (itemizing) {
--              itemize(file, ndx, statret, st,
+-                      if (!unchanged_file(cmpbuf, file, &alt_st))
++                      if (!unchanged_file(cmpbuf, file, &alt_sx.st))
+                               continue;
+                       statret = 1;
+-                      *stp = alt_st;
+-                      if (unchanged_attrs(file, &alt_st))
++#ifdef SUPPORT_ACLS
++                      if (preserve_acls)
++                              get_acl(cmpbuf, &alt_sx);
++#endif
++                      if (unchanged_attrs(file, &alt_sx))
+                               break;
+               } while (basis_dir[++j] != NULL);
++              if (statret == 1) {
++                      sxp->st = alt_sx.st;
 +#ifdef SUPPORT_ACLS
-+              if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
-+                      get_acl(fname, sxp);
++                      if (preserve_acls) {
++                              if (!ACL_READY(*sxp))
++                                      get_acl(cmpbuf, sxp);
++                              else {
++                                      sxp->acc_acl = alt_sx.acc_acl;
++                                      sxp->def_acl = alt_sx.def_acl;
++                              }
++                      }
++#endif
++              }
++#ifdef SUPPORT_ACLS
++              else if (preserve_acls)
++                      free_acl(&alt_sx);
 +#endif
-+              itemize(file, ndx, statret, sxp,
-                       ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
-                       terse ? "" : toname);
        }
-@@ -291,14 +304,15 @@ void hard_link_cluster(struct file_struc
- #ifdef SUPPORT_HARD_LINKS
-       char hlink1[MAXPATHLEN];
-       char *hlink2;
--      STRUCT_STAT st1, st2;
-+      statx sx;
+-      if (maybe_hard_link(file, ndx, fname, statret, stp, prev_name, &prev_st,
++      if (maybe_hard_link(file, ndx, fname, statret, sxp, prev_name, &prev_st,
+                           realname, itemizing, code) < 0)
+               return -1;
+@@ -277,7 +308,8 @@ void finish_hard_link(struct file_struct
+                     STRUCT_STAT *stp, int itemizing, enum logcode code,
+                     int alt_dest)
+ {
+-      STRUCT_STAT st, prev_st;
++      statx prev_sx;
 +      STRUCT_STAT st;
-       int statret, ndx = master;
-       struct hlist *hl = F_HLIST(file);
+       char alt_name[MAXPATHLEN], *prev_name;
+       const char *our_name;
+       int prev_statret, ndx, prev_ndx = F_HL_PREV(file);
+@@ -301,14 +333,24 @@ void finish_hard_link(struct file_struct
+       } else
+               our_name = fname;
  
-       hl->hlindex = FINISHED_LINK;
-       if (dry_run)
-               hl->dest_used = dest_used + 1;
--      if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
-+      if (link_stat(f_name(file, hlink1), &st, 0) < 0)
-               return;
-       if (!(file->flags & FLAG_HLINK_FIRST)) {
-               while (!(file->flags & FLAG_HLINK_LAST)) {
-@@ -314,9 +328,13 @@ void hard_link_cluster(struct file_struc
-               if (hl->hlindex != SKIPPED_LINK)
-                       continue;
-               hlink2 = f_name(file, NULL);
--              statret = link_stat(hlink2, &st2, 0);
--              maybe_hard_link(file, ndx, hlink2, statret, &st2,
--                              hlink1, &st1, itemizing, code);
-+              statret = link_stat(hlink2, &sx.st, 0);
-+              maybe_hard_link(file, ndx, hlink2, statret, &sx,
-+                              hlink1, &st, itemizing, code);
++#ifdef SUPPORT_ACLS
++      prev_sx.acc_acl = prev_sx.def_acl = NULL;
++#endif
++
+       while ((ndx = prev_ndx) >= 0) {
++              int val;
+               file = FPTR(ndx);
+               file->flags = (file->flags & ~FLAG_HLINK_FIRST) | FLAG_HLINK_DONE;
+               prev_ndx = F_HL_PREV(file);
+               prev_name = f_name(file, NULL);
+-              prev_statret = link_stat(prev_name, &prev_st, 0);
+-              if (maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_st,
+-                                  our_name, stp, fname, itemizing, code) < 0)
++              prev_statret = link_stat(prev_name, &prev_sx.st, 0);
++              val = maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_sx,
++                                    our_name, stp, fname, itemizing, code);
 +#ifdef SUPPORT_ACLS
 +              if (preserve_acls)
-+                      free_acl(&sx);
++                      free_acl(&prev_sx);
 +#endif
++              if (val < 0)
+                       continue;
                if (remove_source_files == 1 && do_xfers)
                        send_msg_int(MSG_SUCCESS, ndx);
-               hl->hlindex = FINISHED_LINK;
 --- old/lib/sysacls.c
 +++ new/lib/sysacls.c
 @@ -0,0 +1,3251 @@
@@ -5591,7 +5596,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +#endif /* SUPPORT_ACLS */
 --- old/log.c
 +++ new/log.c
-@@ -618,8 +618,10 @@ static void log_formatted(enum logcode c
+@@ -625,8 +625,10 @@ static void log_formatted(enum logcode c
                        c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
                        c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
                        c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
@@ -5699,11 +5704,11 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
                        /* A large opt value means that set_refuse_options()
                         * turned this option off. */
 @@ -1223,6 +1253,8 @@ int parse_arguments(int *argc, const cha
-               preserve_uid = flist_extra_ndx++;
+               preserve_uid = ++flist_extra_cnt;
        if (preserve_gid)
-               preserve_gid = flist_extra_ndx++;
+               preserve_gid = ++flist_extra_cnt;
 +      if (preserve_acls)
-+              preserve_acls = flist_extra_ndx++;
++              preserve_acls = ++flist_extra_cnt;
  
        *argv = poptGetArgs(pc);
        *argc = count_args(*argv);
@@ -5720,7 +5725,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
        if (preserve_gid)
 --- old/receiver.c
 +++ new/receiver.c
-@@ -48,6 +48,7 @@ extern int keep_partial;
+@@ -47,6 +47,7 @@ extern int keep_partial;
  extern int checksum_seed;
  extern int inplace;
  extern int delay_updates;
@@ -5728,7 +5733,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  extern struct stats stats;
  extern char *stdout_format;
  extern char *tmpdir;
-@@ -348,6 +349,10 @@ int recv_files(int f_in, struct file_lis
+@@ -347,6 +348,10 @@ int recv_files(int f_in, struct file_lis
        int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
        enum logcode log_code = log_before_transfer ? FLOG : FINFO;
        int max_phase = protocol_version >= 29 ? 2 : 1;
@@ -5736,10 +5741,10 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +#ifdef SUPPORT_ACLS
 +      const char *parent_dirname = "";
 +#endif
-       int i, recv_ok;
+       int ndx, recv_ok;
  
        if (verbose > 2)
-@@ -551,7 +556,16 @@ int recv_files(int f_in, struct file_lis
+@@ -545,7 +550,16 @@ int recv_files(int f_in, struct file_lis
                 * mode based on the local permissions and some heuristics. */
                if (!preserve_perms) {
                        int exists = fd1 != -1;
@@ -5922,8 +5927,8 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +#endif
 +
  #ifdef HAVE_CHMOD
--      if ((st->st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
-+      if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
+-      if (!BITS_EQUAL(st->st_mode, new_mode, CHMOD_BITS)) {
++      if (!BITS_EQUAL(sxp->st.st_mode, new_mode, CHMOD_BITS)) {
                int ret = do_chmod(fname, new_mode);
                if (ret < 0) {
                        rsyserr(FERROR, errno,
@@ -5948,7 +5953,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  
 --- old/rsync.h
 +++ new/rsync.h
-@@ -495,6 +495,14 @@ struct idev {
+@@ -502,6 +502,14 @@ struct idev {
  #define IN_LOOPBACKNET 127
  #endif
  
@@ -5962,21 +5967,21 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +
  #define GID_NONE ((gid_t)-1)
  
- #define HL_CHECK_MASTER       0
-@@ -540,10 +548,12 @@ union flist_extras {
- /* When enabled, all entries have these: */
- #define F_UID(f) FLIST_EXTRA(f, preserve_uid).uid
- #define F_GID(f) FLIST_EXTRA(f, preserve_gid).gid
-+#define F_ACL(f) FLIST_EXTRA(f, preserve_acls).num
+ struct file_struct {
+@@ -553,10 +561,12 @@ extern int preserve_gid;
+ /* When the associated option is on, all entries will have these present: */
+ #define F_UID(f) REQ_EXTRA(f, preserve_uid)->uid
+ #define F_GID(f) REQ_EXTRA(f, preserve_gid)->gid
++#define F_ACL(f) REQ_EXTRA(f, preserve_acls)->unum
  
- /* These are per-entry optional and mutally exclusive: */
- #define F_IDEV(f) FLIST_EXTRA(f, flist_extra_ndx).idev
- #define F_HLIST(f) FLIST_EXTRA(f, flist_extra_ndx).hlist
-+#define F_DEFACL(f) FLIST_EXTRA(f, flist_extra_ndx).num
+ /* These items are per-entry optional and mutally exclusive: */
+ #define F_HL_IDEV(f) OPT_EXTRA(f, LEN64_BUMP(f))->idev
+ #define F_HL_PREV(f) OPT_EXTRA(f, LEN64_BUMP(f))->num
++#define F_DEF_ACL(f) OPT_EXTRA(f, LEN64_BUMP(f))->unum
  
- /* These are per-entry optional, but always both or neither: */
- #define F_DMAJOR(f) FLIST_EXTRA(f, flist_extra_ndx + (IS_HLINKED(f)? 1 : 0)).num
-@@ -667,6 +677,17 @@ struct stats {
+ /* This optional item might follow an F_HL_*() item.
+  * (Note: a device doesn't need to check LEN64_BUMP(f).) */
+@@ -692,6 +702,17 @@ struct stats {
  
  struct chmod_mode_struct;
  
@@ -5994,7 +5999,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  #include "byteorder.h"
  #include "lib/mdfour.h"
  #include "lib/wildmatch.h"
-@@ -685,6 +706,16 @@ struct chmod_mode_struct;
+@@ -710,6 +731,16 @@ struct chmod_mode_struct;
  #define NORETURN __attribute__((__noreturn__))
  #endif
  
@@ -6692,7 +6697,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  EOT
  diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
  
-@@ -186,15 +186,15 @@ $RSYNC -ivvplrtH --link-dest="$todir" "$
+@@ -185,15 +185,15 @@ $RSYNC -ivvplrtH --link-dest="$todir" "$
      | tee "$outfile"
  filter_outfile
  cat <<EOT >"$chkfile"
@@ -6717,9 +6722,9 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
  EOT
  diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
  
-@@ -236,14 +236,14 @@ filter_outfile
- # TODO fix really-old problem when combining -H with --compare-dest:
- # missing output for foo/extra hard-link (and it might not be updated)!
+@@ -233,15 +233,15 @@ $RSYNC -ivvplrtH --compare-dest="$todir"
+     | tee "$outfile"
+ filter_outfile
  cat <<EOT >"$chkfile"
 -cd        ./
 -cd        bar/
@@ -6728,6 +6733,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 -cd        foo/
 -.f        foo/config1
 -.f        foo/config2
+-.f        foo/extra
 -.L        foo/sym -> ../bar/baz/rsync
 +cd          ./
 +cd          bar/
@@ -6736,6 +6742,7 @@ latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 +cd          foo/
 +.f          foo/config1
 +.f          foo/config2
++.f          foo/extra
 +.L          foo/sym -> ../bar/baz/rsync
  EOT
  diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"