moved file deletion to before the fork() to prevent a race condition
authorAndrew Tridgell <tridge@samba.org>
Mon, 24 Jan 2000 11:20:25 +0000 (11:20 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 24 Jan 2000 11:20:25 +0000 (11:20 +0000)
pointed out by byrnes@curl.com

main.c
receiver.c

diff --git a/main.c b/main.c
index 6ea9321..a546778 100644 (file)
--- a/main.c
+++ b/main.c
@@ -280,10 +280,20 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
        int recv_pipe[2];
        int error_pipe[2];
        extern int preserve_hard_links;
        int recv_pipe[2];
        int error_pipe[2];
        extern int preserve_hard_links;
+       extern int delete_after;
+       extern int recurse;
+       extern int delete_mode;
 
        if (preserve_hard_links)
                init_hard_links(flist);
 
 
        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) {
+                       delete_files(flist);
+               }
+       }
+
        if (pipe(recv_pipe) < 0) {
                rprintf(FERROR,"pipe failed in do_recv\n");
                exit_cleanup(RERR_SOCKETIO);
        if (pipe(recv_pipe) < 0) {
                rprintf(FERROR,"pipe failed in do_recv\n");
                exit_cleanup(RERR_SOCKETIO);
index 20afb4f..6647c68 100644 (file)
@@ -102,7 +102,7 @@ static void delete_one(struct file_struct *f)
 /* this deletes any files on the receiving side that are not present
    on the sending side. For version 1.6.4 I have changed the behaviour
    to match more closely what most people seem to expect of this option */
 /* this deletes any files on the receiving side that are not present
    on the sending side. For version 1.6.4 I have changed the behaviour
    to match more closely what most people seem to expect of this option */
-static void delete_files(struct file_list *flist)
+void delete_files(struct file_list *flist)
 {
        struct file_list *local_file_list;
        int i, j;
 {
        struct file_list *local_file_list;
        int i, j;
@@ -316,12 +316,6 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
                rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
        }
 
                rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
        }
 
-       if (!delete_after) {
-               if (recurse && delete_mode && !local_name && flist->count>0) {
-                       delete_files(flist);
-               }
-       }
-
        while (1) {      
                cleanup_disable();
 
        while (1) {      
                cleanup_disable();