A slightly better reset mechanism for send_file_entry() and
authorWayne Davison <wayned@samba.org>
Sat, 10 Jan 2004 22:13:19 +0000 (22:13 +0000)
committerWayne Davison <wayned@samba.org>
Sat, 10 Jan 2004 22:13:19 +0000 (22:13 +0000)
receive_file_entry().

batch.c
flist.c

diff --git a/batch.c b/batch.c
index 753eae9..4560a91 100644 (file)
--- a/batch.c
+++ b/batch.c
@@ -45,7 +45,6 @@ void write_batch_flist_info(int flist_count, struct file_struct **files)
        write_int(f, protocol_version);
        write_int(f, flist_count);
 
        write_int(f, protocol_version);
        write_int(f, flist_count);
 
-       reset_file_entry_vars();
        for (i = 0; i < flist_count; i++)
                send_file_entry(files[i], f, files[i]->flags & LIVE_FLAGS);
        send_file_entry(NULL, f, 0);
        for (i = 0; i < flist_count; i++)
                send_file_entry(files[i], f, files[i]->flags & LIVE_FLAGS);
        send_file_entry(NULL, f, 0);
@@ -157,7 +156,7 @@ struct file_list *create_flist_from_batch(void)
                        flags |= read_byte(f) << 8;
                receive_file_entry(&batch_flist->files[i], flags, f);
        }
                        flags |= read_byte(f) << 8;
                receive_file_entry(&batch_flist->files[i], flags, f);
        }
-       reset_file_entry_vars();
+       receive_file_entry(NULL, 0, 0); /* Signal that we're done. */
 
        protocol_version = save_pv;
        stats.total_read = save_read;
 
        protocol_version = save_pv;
        stats.total_read = save_read;
diff --git a/flist.c b/flist.c
index 4160534..0601901 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -351,32 +351,16 @@ static void flist_expand(struct file_list *flist)
        }
 }
 
        }
 }
 
-/* These vars are used by both send_file_entry() and receive_file_entry()
- * (but just one at a time).  They have been placed outside these functions
- * so that we can reset the values when the batch-processing wants to make
- * extra use of these functions (which needs to start from a known state). */
-static time_t modtime;
-static mode_t mode;
-static DEV64_T rdev;   /* just high bytes in p28 onward */
-static uid_t uid;
-static gid_t gid;
-static DEV64_T dev;
-static char lastname[MAXPATHLEN];
-
-void reset_file_entry_vars(void)
-{
-       modtime = 0;
-       mode = 0;
-       rdev = 0;
-       uid = 0;
-       gid = 0;
-       dev = 0;
-       *lastname = '\0';
-}
-
 void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
 {
        unsigned short flags;
 void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
 {
        unsigned short flags;
+       static time_t modtime;
+       static mode_t mode;
+       static DEV64_T rdev;    /* just high bytes in p28 onward */
+       static DEV64_T dev;
+       static uid_t uid;
+       static gid_t gid;
+       static char lastname[MAXPATHLEN];
        char *fname, fbuf[MAXPATHLEN];
        int l1, l2;
 
        char *fname, fbuf[MAXPATHLEN];
        int l1, l2;
 
@@ -385,6 +369,10 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
 
        if (!file) {
                write_byte(f, 0);
 
        if (!file) {
                write_byte(f, 0);
+               modtime = 0, mode = 0;
+               rdev = 0, dev = 0;
+               uid = 0, gid = 0;
+               *lastname = '\0';
                return;
        }
 
                return;
        }
 
@@ -531,11 +519,26 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
 
 void receive_file_entry(struct file_struct **fptr, unsigned short flags, int f)
 {
 
 void receive_file_entry(struct file_struct **fptr, unsigned short flags, int f)
 {
+       static time_t modtime;
+       static mode_t mode;
+       static DEV64_T rdev;    /* just high bytes in p28 onward */
+       static DEV64_T dev;
+       static uid_t uid;
+       static gid_t gid;
+       static char lastname[MAXPATHLEN];
        char thisname[MAXPATHLEN];
        unsigned int l1 = 0, l2 = 0;
        char *p;
        struct file_struct *file;
 
        char thisname[MAXPATHLEN];
        unsigned int l1 = 0, l2 = 0;
        char *p;
        struct file_struct *file;
 
+       if (!fptr) {
+               modtime = 0, mode = 0;
+               rdev = 0, dev = 0;
+               uid = 0, gid = 0;
+               *lastname = '\0';
+               return;
+       }
+
        if (flags & SAME_NAME)
                l1 = read_byte(f);
 
        if (flags & SAME_NAME)
                l1 = read_byte(f);
 
@@ -1190,7 +1193,7 @@ struct file_list *recv_file_list(int f)
                                f_name(flist->files[i]));
                }
        }
                                f_name(flist->files[i]));
                }
        }
-
+       receive_file_entry(NULL, 0, 0); /* Signal that we're done. */
 
        if (verbose > 2)
                rprintf(FINFO, "received %d names\n", flist->count);
 
        if (verbose > 2)
                rprintf(FINFO, "received %d names\n", flist->count);