Applying uid/gid fix from trunk.
[rsync-patches.git] / xattrs.diff
index 4214ca93ead96b759e61b328f0f305ce6ee29826..4446c7ce5a795995c38797a5b7fdfc43ccd6354a 100644 (file)
@@ -10,12 +10,13 @@ To use this patch, run these commands for a successful build:
     ./configure                         (optional if already run)
     make
 
---- old/compat.c
-+++ new/compat.c
-@@ -115,13 +115,6 @@ void setup_protocol(int f_out,int f_in)
-                           protocol_version);
-                       exit_cleanup(RERR_PROTOCOL);
-               }
+diff --git a/compat.c b/compat.c
+--- a/compat.c
++++ b/compat.c
+@@ -190,13 +190,6 @@ void setup_protocol(int f_out,int f_in)
+       if (protocol_version < 30) {
+               if (append_mode == 1)
+                       append_mode = 2;
 -              if (preserve_xattrs && !local_server) {
 -                      rprintf(FERROR,
 -                          "--xattrs requires protocol 30 or higher"
@@ -26,25 +27,26 @@ To use this patch, run these commands for a successful build:
        }
  
        if (delete_mode && !(delete_before+delete_during+delete_after)) {
---- old/xattrs.c
-+++ new/xattrs.c
-@@ -20,6 +20,7 @@
-  */
+diff --git a/xattrs.c b/xattrs.c
+--- a/xattrs.c
++++ b/xattrs.c
+@@ -21,6 +21,7 @@
  
  #include "rsync.h"
+ #include "ifuncs.h"
 +#include "io.h"
  #include "lib/sysxattrs.h"
  
  #ifdef SUPPORT_XATTRS
-@@ -31,6 +32,7 @@ extern int am_generator;
- extern int read_only;
+@@ -33,6 +34,7 @@ extern int read_only;
  extern int list_only;
+ extern int preserve_xattrs;
  extern int checksum_seed;
 +extern int protocol_version;
  
  #define RSYNC_XAL_INITIAL 5
  #define RSYNC_XAL_LIST_INITIAL 100
-@@ -222,7 +224,7 @@ static int rsync_xal_get(const char *fna
+@@ -246,7 +248,7 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
                if (!(ptr = get_xattr_data(fname, name, &datum_len, 0)))
                        return -1;
  
@@ -53,7 +55,7 @@ To use this patch, run these commands for a successful build:
                        /* For large datums, we store a flag and a checksum. */
                        name_offset = 1 + MAX_DIGEST_LEN;
                        sum_init(checksum_seed);
-@@ -278,7 +280,7 @@ static int find_matching_xattr(item_list
+@@ -348,7 +350,7 @@ static int find_matching_xattr(item_list *xalp)
                         || rxas1[j].datum_len != rxas2[j].datum_len
                         || strcmp(rxas1[j].name, rxas2[j].name))
                                break;
@@ -62,7 +64,7 @@ To use this patch, run these commands for a successful build:
                                if (memcmp(rxas1[j].datum + 1,
                                           rxas2[j].datum + 1,
                                           MAX_DIGEST_LEN) != 0)
-@@ -315,34 +317,43 @@ int send_xattr(statx *sxp, int f)
+@@ -385,13 +387,22 @@ int send_xattr(stat_x *sxp, int f)
  {
        int ndx = find_matching_xattr(sxp->xattr);
  
@@ -86,37 +88,29 @@ To use this patch, run these commands for a successful build:
 -              write_varint(f, count);
 +              write_varint30(f, count);
                for (rxa = sxp->xattr->items; count--; rxa++) {
- #ifdef HAVE_LINUX_XATTRS
--                      write_varint(f, rxa->name_len);
+                       size_t name_len = rxa->name_len;
+                       const char *name = rxa->name;
+@@ -410,8 +421,8 @@ int send_xattr(stat_x *sxp, int f)
+                               name_len += UPRE_LEN;
+                       }
+ #endif
+-                      write_varint(f, name_len);
 -                      write_varint(f, rxa->datum_len);
-+                      write_varint30(f, rxa->name_len);
++                      write_varint30(f, name_len);
 +                      write_varint30(f, rxa->datum_len);
-                       write_buf(f, rxa->name, rxa->name_len);
- #else
-                       /* We strip the rsync prefix from disguised namespaces
-                        * and put everything else in the user namespace. */
-                       if (HAS_PREFIX(rxa->name, RSYNC_PREFIX)
-                        && rxa->name[RPRE_LEN] != '%') {
--                              write_varint(f, rxa->name_len - RPRE_LEN);
--                              write_varint(f, rxa->datum_len);
-+                              write_varint30(f, rxa->name_len - RPRE_LEN);
-+                              write_varint30(f, rxa->datum_len);
-                               write_buf(f, rxa->name + RPRE_LEN, rxa->name_len - RPRE_LEN);
-                       } else {
--                              write_varint(f, rxa->name_len + UPRE_LEN);
--                              write_varint(f, rxa->datum_len);
-+                              write_varint30(f, rxa->name_len + UPRE_LEN);
-+                              write_varint30(f, rxa->datum_len);
+ #ifndef HAVE_LINUX_XATTRS
+                       if (name_len > rxa->name_len) {
                                write_buf(f, USER_PREFIX, UPRE_LEN);
-                               write_buf(f, rxa->name, rxa->name_len);
+@@ -419,7 +430,7 @@ int send_xattr(stat_x *sxp, int f)
                        }
  #endif
+                       write_buf(f, name, name_len);
 -                      if (rxa->datum_len > MAX_FULL_DATUM)
 +                      if (rxa->datum_len > MAX_FULL_DATUM && protocol_version >= 30)
                                write_buf(f, rxa->datum + 1, MAX_DIGEST_LEN);
                        else
                                write_buf(f, rxa->datum, rxa->datum_len);
-@@ -392,7 +403,7 @@ int xattr_diff(struct file_struct *file,
+@@ -469,7 +480,7 @@ int xattr_diff(struct file_struct *file, stat_x *sxp, int find_all)
                cmp = rec_cnt ? strcmp(snd_rxa->name, rec_rxa->name) : -1;
                if (cmp > 0)
                        same = 0;
@@ -125,30 +119,30 @@ To use this patch, run these commands for a successful build:
                        same = cmp == 0 && snd_rxa->datum_len == rec_rxa->datum_len
                            && memcmp(snd_rxa->datum + 1, rec_rxa->datum + 1,
                                      MAX_DIGEST_LEN) == 0;
-@@ -435,6 +446,9 @@ void send_xattr_request(const char *fnam
-       int j, cnt, prior_req = -1;
+@@ -514,6 +525,9 @@ void send_xattr_request(const char *fname, struct file_struct *file, int f_out)
+       int cnt, prior_req = 0;
        rsync_xa *rxa;
  
 +      if (protocol_version < 30)
 +              return;
 +
        lst += F_XATTR(file);
-       cnt = lst->count;
-       for (rxa = lst->items, j = 0; j < cnt; rxa++, j++) {
-@@ -506,6 +520,9 @@ void recv_xattr_request(struct file_stru
+       for (rxa = lst->items, cnt = lst->count; cnt--; rxa++) {
+               if (rxa->datum_len <= MAX_FULL_DATUM)
+@@ -570,6 +584,9 @@ int recv_xattr_request(struct file_struct *file, int f_in)
        rsync_xa *rxa;
-       int rel_pos, cnt;
+       int rel_pos, cnt, num, got_xattr_data = 0;
  
 +      if (protocol_version < 30)
-+              return;
++              return 0;
 +
        if (F_XATTR(file) < 0) {
                rprintf(FERROR, "recv_xattr_request: internal data error!\n");
                exit_cleanup(RERR_STREAMIO);
-@@ -552,7 +569,22 @@ void receive_xattr(struct file_struct *f
- {
-       static item_list temp_xattr = EMPTY_ITEM_LIST;
-       int count;
+@@ -632,7 +649,22 @@ void receive_xattr(struct file_struct *file, int f)
+ #else
+       int need_sort = 1;
+ #endif
 -      int ndx = read_varint(f);
 +      int ndx;
 +
@@ -169,7 +163,7 @@ To use this patch, run these commands for a successful build:
  
        if (ndx < 0 || (size_t)ndx > rsync_xal_l.count) {
                rprintf(FERROR, "receive_xattr: xa index %d out of"
-@@ -565,7 +597,7 @@ void receive_xattr(struct file_struct *f
+@@ -645,7 +677,7 @@ void receive_xattr(struct file_struct *file, int f)
                return;
        }
        
@@ -178,8 +172,8 @@ To use this patch, run these commands for a successful build:
                (void)EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count);
                temp_xattr.count = 0;
        }
-@@ -573,9 +605,10 @@ void receive_xattr(struct file_struct *f
-       while (count--) {
+@@ -653,9 +685,10 @@ void receive_xattr(struct file_struct *file, int f)
+       for (num = 1; num <= count; num++) {
                char *ptr, *name;
                rsync_xa *rxa;
 -              size_t name_len = read_varint(f);
@@ -189,6 +183,6 @@ To use this patch, run these commands for a successful build:
 +              size_t datum_len = read_varint30(f);
 +              size_t dget_len = datum_len > MAX_FULL_DATUM && protocol_version >= 30
 +                              ? 1 + MAX_DIGEST_LEN : datum_len;
- #ifdef HAVE_LINUX_XATTRS
-               size_t extra_len = 0;
- #else
+               size_t extra_len = MIGHT_NEED_RPRE ? RPRE_LEN : 0;
+               if ((dget_len + extra_len < dget_len)
+                || (dget_len + extra_len + name_len < dget_len))