replace calls to strcmp() with a u_strcmp() function that uses only
[rsync.git] / flist.c
diff --git a/flist.c b/flist.c
index 7b2c985cb1329e71313c1dc29c38be9b4f318d66..759206909f0d8b8475d6a23f018d42b8dbba48a0 100644 (file)
--- a/flist.c
+++ b/flist.c
 
 #include "rsync.h"
 
+extern struct stats stats;
+
 extern int csum_length;
 
 extern int verbose;
 extern int am_server;
 extern int always_checksum;
-extern int64 total_size;
 
 extern int cvs_exclude;
 
@@ -90,49 +91,6 @@ static void send_directory(int f,struct file_list *flist,char *dir);
 
 static char *flist_dir;
 
-static void clean_fname(char *name)
-{
-  char *p;
-  int l;
-  int modified = 1;
-
-  if (!name) return;
-
-  while (modified) {
-    modified = 0;
-
-    if ((p=strstr(name,"/./"))) {
-      modified = 1;
-      while (*p) {
-       p[0] = p[2];
-       p++;
-      }
-    }
-
-    if ((p=strstr(name,"//"))) {
-      modified = 1;
-      while (*p) {
-       p[0] = p[1];
-       p++;
-      }
-    }
-
-    if (strncmp(p=name,"./",2) == 0) {      
-      modified = 1;
-      do {
-       p[0] = p[2];
-      } while (*p++);
-    }
-
-    l = strlen(p=name);
-    if (l > 1 && p[l-1] == '/') {
-      modified = 1;
-      p[l-1] = 0;
-    }
-  }
-}
-
-
 
 void send_file_entry(struct file_struct *file,int f,unsigned base_flags)
 {
@@ -169,6 +127,11 @@ void send_file_entry(struct file_struct *file,int f,unsigned base_flags)
   if (l1 > 0) flags |= SAME_NAME;
   if (l2 > 255) flags |= LONG_NAME;
 
+  /* we must make sure we don't send a zero flags byte or the other
+     end will terminate the flist transfer */
+  if (flags == 0 && !S_ISDIR(file->mode)) flags |= FLAG_DELETE;
+  if (flags == 0) flags |= LONG_NAME;
+
   write_byte(f,flags);  
   if (flags & SAME_NAME)
     write_byte(f,l1);
@@ -459,7 +422,7 @@ static struct file_struct *make_file(char *fname)
        }
 
        if (!S_ISDIR(st.st_mode))
-               total_size += st.st_size;
+               stats.total_size += st.st_size;
 
        return file;
 }
@@ -561,15 +524,17 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
        int i,l;
        STRUCT_STAT st;
        char *p,*dir;
-       char dbuf[MAXPATHLEN];
        char lastpath[MAXPATHLEN]="";
        struct file_list *flist;
+       int64 start_write;
 
        if (verbose && recurse && !am_server && f != -1) {
                rprintf(FINFO,"building file list ... ");
                rflush(FINFO);
        }
 
+       start_write = stats.total_written;
+
        flist = (struct file_list *)malloc(sizeof(flist[0]));
        if (!flist) out_of_memory("send_file_list");
 
@@ -641,24 +606,23 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
                        fname = ".";
                
                if (dir && *dir) {
-                       if (getcwd(dbuf,MAXPATHLEN-1) == NULL) {
-                               rprintf(FERROR,"getwd : %s\n",strerror(errno));
-                               exit_cleanup(1);
-                       }
-                       if (chdir(dir) != 0) {
+                       char *olddir = push_dir(dir, 1);
+
+                       if (!olddir) {
                                io_error=1;
-                               rprintf(FERROR,"chdir %s : %s\n",
+                               rprintf(FERROR,"push_dir %s : %s\n",
                                        dir,strerror(errno));
                                continue;
                        }
+
                        flist_dir = dir;
                        if (one_file_system)
                                set_filesystem(fname);
                        send_file_name(f,flist,fname,recurse,FLAG_DELETE);
                        flist_dir = NULL;
-                       if (chdir(dbuf) != 0) {
-                               rprintf(FERROR,"chdir %s : %s\n",
-                                       dbuf,strerror(errno));
+                       if (pop_dir(olddir) != 0) {
+                               rprintf(FERROR,"pop_dir %s : %s\n",
+                                       dir,strerror(errno));
                                exit_cleanup(1);
                        }
                        continue;
@@ -691,7 +655,8 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
 
        if (f != -1) {
                io_end_buffering(f);
-               write_flush(f);
+               stats.flist_size = stats.total_written - start_write;
+               stats.num_files = flist->count;
        }
 
        if (verbose > 2)
@@ -705,12 +670,15 @@ struct file_list *recv_file_list(int f)
 {
   struct file_list *flist;
   unsigned char flags;
+  int64 start_read;
 
   if (verbose && recurse && !am_server) {
     rprintf(FINFO,"receiving file list ... ");
     rflush(FINFO);
   }
 
+  start_read = stats.total_read;
+
   flist = (struct file_list *)malloc(sizeof(flist[0]));
   if (!flist)
     goto oom;
@@ -741,7 +709,7 @@ struct file_list *recv_file_list(int f)
     receive_file_entry(&flist->files[i],flags,f);
 
     if (S_ISREG(flist->files[i]->mode))
-      total_size += flist->files[i]->length;
+           stats.total_size += flist->files[i]->length;
 
     flist->count++;
 
@@ -772,6 +740,9 @@ struct file_list *recv_file_list(int f)
   if (verbose > 2)
     rprintf(FINFO,"recv_file_list done\n");
 
+  stats.flist_size = stats.total_read - start_read;
+  stats.num_files = flist->count;
+
   return flist;
 
 oom:
@@ -786,8 +757,8 @@ int file_compare(struct file_struct **f1,struct file_struct **f2)
        if (!(*f1)->basename) return -1;
        if (!(*f2)->basename) return 1;
        if ((*f1)->dirname == (*f2)->dirname)
-               return strcmp((*f1)->basename, (*f2)->basename);
-       return strcmp(f_name(*f1),f_name(*f2));
+               return u_strcmp((*f1)->basename, (*f2)->basename);
+       return u_strcmp(f_name(*f1),f_name(*f2));
 }