- Added the ability to parse a literal IPv6 address in an "rsync:" URL
[rsync/rsync.git] / main.c
diff --git a/main.c b/main.c
index 715af86..4f3fd90 100644 (file)
--- a/main.c
+++ b/main.c
@@ -43,6 +43,7 @@ extern int local_server;
 extern int log_got_error;
 extern int module_id;
 extern int orig_umask;
+extern int copy_links;
 extern int keep_dirlinks;
 extern int preserve_hard_links;
 extern int protocol_version;
@@ -151,6 +152,8 @@ static void report(int f)
        /* this is the client */
 
        if (!am_sender) {
+               /* Read the first two in opposite order because the meaning of
+                * read/write swaps when switching from sender to receiver. */
                total_written = read_longint(f);
                total_read = read_longint(f);
                stats.total_size = read_longint(f);
@@ -175,15 +178,15 @@ static void report(int f)
                rprintf(FINFO,"Matched data: %.0f bytes\n",
                        (double)stats.matched_data);
                rprintf(FINFO,"File list size: %d\n", stats.flist_size);
-               rprintf(FINFO,"Total bytes written: %.0f\n",
+               rprintf(FINFO,"Total bytes sent: %.0f\n",
                        (double)total_written);
-               rprintf(FINFO,"Total bytes read: %.0f\n",
+               rprintf(FINFO,"Total bytes received: %.0f\n",
                        (double)total_read);
        }
 
        if (verbose || do_stats) {
                rprintf(FINFO,
-                       "\nwrote %.0f bytes  read %.0f bytes  %.2f bytes/sec\n",
+                       "\nsent %.0f bytes  received %.0f bytes  %.2f bytes/sec\n",
                        (double)total_written, (double)total_read,
                        (total_written + total_read)/(0.5 + (t - starttime)));
                rprintf(FINFO, "total size is %.0f  speedup is %.2f\n",
@@ -376,9 +379,13 @@ static char *get_local_name(struct file_list *flist,char *name)
        if (do_mkdir(name,0777 & ~orig_umask) != 0) {
                rsyserr(FERROR, errno, "mkdir %s failed", full_fname(name));
                exit_cleanup(RERR_FILEIO);
-       } else {
-               if (verbose > 0)
-                       rprintf(FINFO,"created directory %s\n",name);
+       }
+       if (verbose > 0)
+               rprintf(FINFO, "created directory %s\n", name);
+
+       if (dry_run) {
+               dry_run++;
+               return NULL;
        }
 
        if (!push_dir(name)) {
@@ -456,14 +463,17 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
        int status = 0;
        int error_pipe[2];
 
+       /* The receiving side mustn't obey this, or an existing symlink that
+        * points to an identical file won't be replaced by the referent. */
+       copy_links = 0;
+
        if (preserve_hard_links)
                init_hard_links(flist);
 
        if (!delete_after) {
                /* I moved this here from recv_files() to prevent a race condition */
-               if (recurse && delete_mode && !local_name && flist->count>0) {
+               if (recurse && delete_mode && !local_name && flist->count > 0)
                        delete_files(flist);
-               }
        }
 
        if (fd_pair(error_pipe) < 0) {
@@ -479,7 +489,7 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
                        close(f_out);
 
                /* we can't let two processes write to the socket at one time */
-               io_multiplexing_close();
+               close_multiplexing_out();
 
                /* set place to send errors */
                set_msg_fd_out(error_pipe[1]);
@@ -498,6 +508,7 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
        }
 
        am_generator = 1;
+       close_multiplexing_in();
        if (write_batch)
                stop_write_batch();
 
@@ -764,15 +775,20 @@ static int start_client(int argc, char *argv[])
                host = argv[0] + strlen(URL_PREFIX);
                p = strchr(host,'/');
                if (p) {
-                       *p = 0;
+                       *p = '\0';
                        path = p+1;
-               } else {
+               } else
                        path = "";
-               }
-               p = strchr(host,':');
+               if (*host == '[' && (p = strchr(host, ']')) != NULL) {
+                       host++;
+                       *p++ = '\0';
+                       if (*p != ':')
+                               p = NULL;
+               } else
+                       p = strchr(host, ':');
                if (p) {
                        rsync_port = atoi(p+1);
-                       *p = 0;
+                       *p = '\0';
                }
                return start_socket_client(host, path, argc-1, argv+1);
        }
@@ -784,7 +800,7 @@ static int start_client(int argc, char *argv[])
                         && remote_filesfrom_file != files_from + 1
                         && strncmp(files_from, argv[0], p-argv[0]+1) != 0) {
                                rprintf(FERROR,
-                                       "--files-from hostname is not transfer hostname\n");
+                                       "--files-from hostname is not the same as the transfer hostname\n");
                                exit_cleanup(RERR_SYNTAX);
                        }
                        if (p[1] == ':') { /* double colon */
@@ -817,15 +833,20 @@ static int start_client(int argc, char *argv[])
                                host = argv[argc-1] + strlen(URL_PREFIX);
                                p = strchr(host,'/');
                                if (p) {
-                                       *p = 0;
+                                       *p = '\0';
                                        path = p+1;
-                               } else {
+                               } else
                                        path = "";
-                               }
-                               p = strchr(host,':');
+                               if (*host == '[' && (p = strchr(host, ']')) != NULL) {
+                                       host++;
+                                       *p++ = '\0';
+                                       if (*p != ':')
+                                               p = NULL;
+                               } else
+                                       p = strchr(host, ':');
                                if (p) {
                                        rsync_port = atoi(p+1);
-                                       *p = 0;
+                                       *p = '\0';
                                }
                                return start_socket_client(host, path, argc-1, argv);
                        }
@@ -835,14 +856,14 @@ static int start_client(int argc, char *argv[])
                         && remote_filesfrom_file != files_from + 1
                         && strncmp(files_from, argv[argc-1], p-argv[argc-1]+1) != 0) {
                                rprintf(FERROR,
-                                       "--files-from hostname is not transfer hostname\n");
+                                       "--files-from hostname is not the same as the transfer hostname\n");
                                exit_cleanup(RERR_SYNTAX);
                        }
                        if (!p) { /* no colon found, so src & dest are local */
                                local_server = 1;
                                if (remote_filesfrom_file) {
                                        rprintf(FERROR,
-                                               "--files-from is remote but transfer is local\n");
+                                               "--files-from cannot be remote when the transfer is local\n");
                                        exit_cleanup(RERR_SYNTAX);
                                }
                        } else if (p[1] == ':') { /* double colon */
@@ -1085,6 +1106,8 @@ int main(int argc,char *argv[])
                                batch_name);
                        exit_cleanup(RERR_FILEIO);
                }
+               if (read_batch)
+                       read_stream_flags(batch_fd);
        }
 
        if (am_daemon && !am_server)