Batch files need to be written with the new subprotocol value
[rsync/rsync.git] / compat.c
index a71e45e..0cfb78f 100644 (file)
--- a/compat.c
+++ b/compat.c
@@ -43,6 +43,7 @@ extern int protocol_version;
 extern int preserve_uid;
 extern int preserve_gid;
 extern int preserve_acls;
+extern int preserve_xattrs;
 extern int preserve_hard_links;
 extern int need_messages_from_generator;
 extern int delete_mode, delete_before, delete_during, delete_after;
@@ -65,6 +66,8 @@ void setup_protocol(int f_out,int f_in)
                preserve_gid = ++file_extra_cnt;
        if (preserve_acls && !am_sender)
                preserve_acls = ++file_extra_cnt;
+       if (preserve_xattrs)
+               preserve_xattrs = ++file_extra_cnt;
 
        if (remote_protocol == 0) {
                if (!read_batch)
@@ -72,6 +75,19 @@ void setup_protocol(int f_out,int f_in)
                remote_protocol = read_int(f_in);
                if (protocol_version > remote_protocol)
                        protocol_version = remote_protocol;
+               /* CVS support: fallback to finalized protocol if incompatible */
+               if (protocol_version >= 30) {
+                       int theirsub, oursub = SUBPROTOCOL_VERSION;
+                       if (!read_batch)
+                               write_varint(f_out, oursub);
+                       theirsub = read_varint(f_in);
+                       if (remote_protocol > PROTOCOL_VERSION)
+                               theirsub = 0; /* 0 == final version */
+                       if (protocol_version < PROTOCOL_VERSION)
+                               oursub = 0;
+                       if (theirsub != oursub)
+                               protocol_version--;
+               }
        }
        if (read_batch && remote_protocol > protocol_version) {
                rprintf(FERROR, "The protocol version in the batch file is too new (%d > %d).\n",
@@ -112,13 +128,20 @@ void setup_protocol(int f_out,int f_in)
                            protocol_version);
                        exit_cleanup(RERR_PROTOCOL);
                }
-               if (preserve_acls) {
+               if (preserve_acls && !local_server) {
                        rprintf(FERROR,
                            "--acls requires protocol 30 or higher"
                            " (negotiated %d).\n",
                            protocol_version);
                        exit_cleanup(RERR_PROTOCOL);
                }
+               if (preserve_xattrs && !local_server) {
+                       rprintf(FERROR,
+                           "--xattrs requires protocol 30 or higher"
+                           " (negotiated %d).\n",
+                           protocol_version);
+                       exit_cleanup(RERR_PROTOCOL);
+               }
        }
 
        if (delete_mode && !(delete_before+delete_during+delete_after)) {