simplified the logic of whether to skip a file or not. The -c
[rsync/rsync.git] / rsync.c
diff --git a/rsync.c b/rsync.c
index 80bc59a..78022fb 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -252,13 +252,36 @@ static int set_perms(char *fname,struct file_struct *file,struct stat *st,
 }
 
 
+/* choose whether to skip a particular file */
+static int skip_file(char *fname,
+                    struct file_struct *file, struct stat *st)
+{
+       if (st->st_size != file->length) {
+               return 0;
+       }
+       
+       /* if always checksum is set then we use the checksum instead 
+          of the file time to determine whether to sync */
+       if (always_checksum && S_ISREG(st->st_mode)) {
+               char sum[MD4_SUM_LENGTH];
+               file_checksum(fname,sum,st->st_size);
+               return (memcmp(sum,file->sum,csum_length) == 0);
+       }
+
+       if (ignore_times) {
+               return 0;
+       }
+
+       return (st->st_mtime == file->modtime);
+}
+
+
 void recv_generator(char *fname,struct file_list *flist,int i,int f_out)
 {  
   int fd;
   struct stat st;
   struct map_struct *buf;
   struct sum_struct *s;
-  char sum[MD4_SUM_LENGTH];
   int statret;
   struct file_struct *file = &flist->files[i];
 
@@ -388,14 +411,7 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out)
     return;
   }
 
-  if (always_checksum && S_ISREG(st.st_mode)) {
-    file_checksum(fname,sum,st.st_size);
-  }
-
-  if (st.st_size == file->length &&
-      ((!ignore_times && st.st_mtime == file->modtime) ||
-       (always_checksum && S_ISREG(st.st_mode) &&        
-       memcmp(sum,file->sum,csum_length) == 0))) {
+  if (skip_file(fname, file, &st)) {
     set_perms(fname,file,&st,1);
     return;
   }
@@ -416,6 +432,7 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out)
 
   if (fd == -1) {
     fprintf(FERROR,"failed to open %s : %s\n",fname,strerror(errno));
+    fprintf(FERROR,"skipping %s\n",fname);
     return;
   }
 
@@ -802,6 +819,11 @@ off_t send_files(struct file_list *flist,int f_out,int f_in)
       if (file->dir) {
        strncpy(fname,file->dir,MAXPATHLEN-1);
        fname[MAXPATHLEN-1] = 0;
+      if (strlen(fname) == MAXPATHLEN-1) {
+        fprintf(FERROR, "send_files failed on long-named directory %s\n",
+                fname);
+        return -1;
+      }
        strcat(fname,"/");
       }
       strncat(fname,file->name,MAXPATHLEN-strlen(fname));