X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/8d9dc9f99db13d42272b7c150f2e6849331ccdc1..2b6b4d539b0aab98b1cbb9d8c639cb12473aae94:/main.c diff --git a/main.c b/main.c index 5a5d5153..4cf4cf60 100644 --- a/main.c +++ b/main.c @@ -43,6 +43,8 @@ static void report(int f) if (!verbose) return; + if (am_server && !am_sender) return; + if (am_server && am_sender) { write_longint(f,read_total()); write_longint(f,write_total()); @@ -146,40 +148,41 @@ static char *get_local_name(struct file_list *flist,char *name) STRUCT_STAT st; extern int orig_umask; - if (do_stat(name,&st) == 0) { - if (S_ISDIR(st.st_mode)) { - if (chdir(name) != 0) { - rprintf(FERROR,"chdir %s : %s (1)\n",name,strerror(errno)); - exit_cleanup(1); - } - return NULL; - } - if (flist->count > 1) { - rprintf(FERROR,"ERROR: destination must be a directory when copying more than 1 file\n"); - exit_cleanup(1); - } - return name; - } - - if (flist->count == 1) - return name; - - if (!name) - return NULL; - - if (do_mkdir(name,0777 & ~orig_umask) != 0) { - rprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno)); - exit_cleanup(1); - } else { - rprintf(FINFO,"created directory %s\n",name); - } - - if (chdir(name) != 0) { - rprintf(FERROR,"chdir %s : %s (2)\n",name,strerror(errno)); - exit_cleanup(1); - } - - return NULL; + if (do_stat(name,&st) == 0) { + if (S_ISDIR(st.st_mode)) { + if (chdir(name) != 0) { + rprintf(FERROR,"chdir %s : %s (1)\n", + name,strerror(errno)); + exit_cleanup(1); + } + return NULL; + } + if (flist->count > 1) { + rprintf(FERROR,"ERROR: destination must be a directory when copying more than 1 file\n"); + exit_cleanup(1); + } + return name; + } + + if (flist->count == 1) + return name; + + if (!name) + return NULL; + + if (do_mkdir(name,0777 & ~orig_umask) != 0) { + rprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno)); + exit_cleanup(1); + } else { + rprintf(FINFO,"created directory %s\n",name); + } + + if (chdir(name) != 0) { + rprintf(FERROR,"chdir %s : %s (2)\n",name,strerror(errno)); + exit_cleanup(1); + } + + return NULL; } @@ -235,7 +238,6 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name) int status=0; int recv_pipe[2]; extern int preserve_hard_links; - extern int am_server; if (preserve_hard_links) init_hard_links(flist); @@ -248,29 +250,26 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name) io_flush(); if ((pid=do_fork()) == 0) { - close(recv_pipe[1]); - io_close_input(f_in); - if (f_in != f_out) close(f_in); - generate_files(f_out,flist,local_name,recv_pipe[0]); + close(recv_pipe[0]); + if (f_in != f_out) close(f_out); + + recv_files(f_in,flist,local_name,recv_pipe[1]); + report(f_in); + + if (verbose > 3) + rprintf(FINFO,"do_recv waiting on %d\n",pid); io_flush(); _exit(0); } - - close(recv_pipe[0]); - if (f_in != f_out) close(f_out); - - recv_files(f_in,flist,local_name,recv_pipe[1]); - if (!am_server) - report(f_in); - - if (verbose > 3) - rprintf(FINFO,"do_recv waiting on %d\n",pid); + close(recv_pipe[1]); + io_close_input(f_in); + if (f_in != f_out) close(f_in); + generate_files(f_out,flist,local_name,recv_pipe[0]); io_flush(); waitpid(pid, &status, 0); - return status; }