added --existing option, similar to one suggested by Gildas Quiniou <gildas@stip.fr>
[rsync/rsync.git] / main.c
diff --git a/main.c b/main.c
index 2846f88..404d49b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -23,8 +23,6 @@ time_t starttime = 0;
 
 struct stats stats;
 
-extern int csum_length;
-
 extern int verbose;
 
 static void report(int f)
@@ -42,8 +40,7 @@ static void report(int f)
                if (f == -1 || !am_sender) return;
        }
 
-       send_stats = verbose || 
-                       ((remote_version >= 20) && (PROTOCOL_VERSION >= 20));
+       send_stats = verbose || (remote_version >= 20);
        if (am_server) {
                if (am_sender && send_stats) {
                        int64 w;
@@ -71,7 +68,7 @@ static void report(int f)
        if (do_stats) {
                if (!am_sender && !send_stats) {
                    /* missing the bytes written by the generator */
-                   rprintf(FINFO, "\nCannot show stats as receiver because protocol version is less than 20\n");
+                   rprintf(FINFO, "\nCannot show stats as receiver because remote protocol version is less than 20\n");
                    rprintf(FINFO, "Use --stats -v to show stats\n");
                    return;
                }
@@ -209,7 +206,7 @@ static char *get_local_name(struct file_list *flist,char *name)
                return name;
        }
 
-       if (flist->count == 1)
+       if (flist->count <= 1)
                return name;
 
        if (do_mkdir(name,0777 & ~orig_umask) != 0) {
@@ -264,10 +261,6 @@ static void do_server_sender(int f_in, int f_out, int argc,char *argv[])
                argv[0] = ".";
        }
        
-       set_nonblocking(f_out);
-       if (f_in != f_out)
-               set_nonblocking(f_in);
-               
        flist = send_file_list(f_out,argc,argv);
        if (!flist || flist->count == 0) {
                exit_cleanup(0);
@@ -301,9 +294,6 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
                close(recv_pipe[0]);
                if (f_in != f_out) close(f_out);
 
-               set_nonblocking(f_in);
-               set_nonblocking(recv_pipe[1]);
-
                recv_files(f_in,flist,local_name,recv_pipe[1]);
                report(f_in);
 
@@ -315,15 +305,12 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
        io_close_input(f_in);
        if (f_in != f_out) close(f_in);
 
-       set_nonblocking(f_out);
-       set_nonblocking(recv_pipe[0]);
-
        io_start_buffering(f_out);
 
        generate_files(f_out,flist,local_name,recv_pipe[0]);
 
        io_flush();
-       waitpid(pid, &status, 0);
+       wait_process(pid, &status);
        return status;
 }
 
@@ -335,6 +322,7 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[])
        char *local_name=NULL;
        char *dir = NULL;
        extern int delete_mode;
+       extern int delete_excluded;
        extern int am_daemon;
 
        if (verbose > 2)
@@ -351,12 +339,12 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[])
                }    
        }
 
-       if (delete_mode)
+       if (delete_mode && !delete_excluded)
                recv_exclude_list(f_in);
 
        flist = recv_file_list(f_in);
-       if (!flist || flist->count == 0) {
-               rprintf(FERROR,"server_recv: nothing to do\n");
+       if (!flist) {
+               rprintf(FERROR,"server_recv: recv_file_list error\n");
                exit_cleanup(RERR_FILESELECT);
        }
        
@@ -378,10 +366,6 @@ void start_server(int f_in, int f_out, int argc, char *argv[])
        extern int cvs_exclude;
        extern int am_sender;
 
-       set_nonblocking(f_out);
-       if (f_in != f_out)
-               set_nonblocking(f_in);
-                       
        setup_protocol(f_out, f_in);
 
        if (am_sender) {
@@ -408,24 +392,21 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[])
        if (am_sender) {
                extern int cvs_exclude;
                extern int delete_mode;
+               extern int delete_excluded;
                if (cvs_exclude)
                        add_cvs_excludes();
-               if (delete_mode) 
+               if (delete_mode && !delete_excluded
                        send_exclude_list(f_out);
                flist = send_file_list(f_out,argc,argv);
                if (verbose > 3) 
                        rprintf(FINFO,"file list sent\n");
 
-               set_nonblocking(f_out);
-               if (f_in != f_out)
-                       set_nonblocking(f_in);
-
                send_files(flist,f_out,f_in);
                if (pid != -1) {
                        if (verbose > 3)
                                rprintf(FINFO,"client_run waiting on %d\n",pid);
                        io_flush();
-                       waitpid(pid, &status, 0);
+                       wait_process(pid, &status);
                }
                report(-1);
                exit_cleanup(status);
@@ -449,7 +430,7 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[])
                if (verbose > 3)
                        rprintf(FINFO,"client_run2 waiting on %d\n",pid);
                io_flush();
-               waitpid(pid, &status, 0);
+               wait_process(pid, &status);
        }
        
        return status | status2;