X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/ba5e128d2344441f25ac4ee8c4b96c31f93bfd81..1d3754aede7d43ec072dd5d4e6cec57094bcd85c:/main.c diff --git a/main.c b/main.c index 67ece95d..fa4fe0f7 100644 --- a/main.c +++ b/main.c @@ -49,7 +49,6 @@ static void report(int f) write_longint(f,read_total()); write_longint(f,write_total()); write_longint(f,total_size); - write_flush(f); return; } @@ -148,40 +147,42 @@ 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 (!push_dir(name, 0)) { + rprintf(FERROR,"push_dir %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 (!push_dir(name, 0)) { + rprintf(FERROR,"push_dir %s : %s (2)\n", + name,strerror(errno)); + exit_cleanup(1); + } + + return NULL; } @@ -198,8 +199,8 @@ static void do_server_sender(int f_in, int f_out, int argc,char *argv[]) if (verbose > 2) rprintf(FINFO,"server_sender starting pid=%d\n",(int)getpid()); - if (!relative_paths && chdir(dir) != 0) { - rprintf(FERROR,"chdir %s: %s (3)\n",dir,strerror(errno)); + if (!relative_paths && !push_dir(dir, 0)) { + rprintf(FERROR,"push_dir %s: %s (3)\n",dir,strerror(errno)); exit_cleanup(1); } argc--; @@ -289,8 +290,8 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[]) dir = argv[0]; argc--; argv++; - if (!am_daemon && chdir(dir) != 0) { - rprintf(FERROR,"chdir %s : %s (4)\n", + if (!am_daemon && !push_dir(dir, 0)) { + rprintf(FERROR,"push_dir %s : %s (4)\n", dir,strerror(errno)); exit_cleanup(1); }