X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/c627d61324e9dcd5df833ee6236dd10415f5bac4..d5ee1f8e7a370884aa9c5353de5129728ed9a37b:/flist.c diff --git a/flist.c b/flist.c index 8bf964d2..fad433a0 100644 --- a/flist.c +++ b/flist.c @@ -21,6 +21,8 @@ #include "rsync.h" +extern int csum_length; + extern int verbose; extern int am_server; extern int always_checksum; @@ -71,24 +73,63 @@ static void send_directory(int f,struct file_list *flist,char *dir); static char *flist_dir = NULL; -static void send_file_entry(struct file_struct *file,int f) +extern void (*send_file_entry)(struct file_struct *file,int f); +extern void (*receive_file_entry)(struct file_struct *file, + unsigned char flags,int f); + + +void send_file_entry_v11(struct file_struct *file,int f) { + unsigned char flags; + static time_t last_time=0; + static mode_t last_mode=0; + static dev_t last_dev=0; + static uid_t last_uid=0; + static gid_t last_gid=0; + static char lastname[MAXPATHLEN]=""; + int l1,l2; + if (f == -1) return; - write_int(f,strlen(file->name)); - write_buf(f,file->name,strlen(file->name)); - write_int(f,(int)file->modtime); + if (!file) { + write_byte(f,0); + return; + } + + flags = FILE_VALID; + + if (file->mode == last_mode) flags |= SAME_MODE; + if (file->dev == last_dev) flags |= SAME_DEV; + if (file->uid == last_uid) flags |= SAME_UID; + if (file->gid == last_gid) flags |= SAME_GID; + if (file->modtime == last_time) flags |= SAME_TIME; + + for (l1=0;lastname[l1] && file->name[l1] == lastname[l1];l1++) ; + l2 = strlen(file->name) - l1; + + if (l1 > 0) flags |= SAME_NAME; + if (l2 > 255) flags |= LONG_NAME; + + write_byte(f,flags); + if (flags & SAME_NAME) + write_byte(f,l1); + if (flags & LONG_NAME) + write_int(f,l2); + else + write_byte(f,l2); + write_buf(f,file->name+l1,l2); + write_int(f,(int)file->length); - write_int(f,(int)file->mode); - if (preserve_uid) + if (!(flags & SAME_TIME)) + write_int(f,(int)file->modtime); + if (!(flags & SAME_MODE)) + write_int(f,(int)file->mode); + if (preserve_uid && !(flags & SAME_UID)) write_int(f,(int)file->uid); - if (preserve_gid) + if (preserve_gid && !(flags & SAME_GID)) write_int(f,(int)file->gid); - if (preserve_devices) { - if (verbose > 2) - fprintf(stderr,"dev=0x%x\n",(int)file->dev); + if (preserve_devices && IS_DEVICE(file->mode) && !(flags & SAME_DEV)) write_int(f,(int)file->dev); - } #if SUPPORT_LINKS if (preserve_links && S_ISLNK(file->mode)) { @@ -98,11 +139,82 @@ static void send_file_entry(struct file_struct *file,int f) #endif if (always_checksum) { - write_buf(f,file->sum,SUM_LENGTH); + write_buf(f,file->sum,csum_length); } + + last_mode = file->mode; + last_dev = file->dev; + last_uid = file->uid; + last_gid = file->gid; + last_time = file->modtime; + + strcpy(lastname,file->name); + lastname[255] = 0; } + +void receive_file_entry_v11(struct file_struct *file, + unsigned char flags,int f) +{ + static mode_t last_time=0; + static mode_t last_mode=0; + static dev_t last_dev=0; + static uid_t last_uid=0; + static gid_t last_gid=0; + static char lastname[MAXPATHLEN]=""; + int l1=0,l2=0; + + if (flags & SAME_NAME) + l1 = read_byte(f); + + if (flags & LONG_NAME) + l2 = read_int(f); + else + l2 = read_byte(f); + + file->name = (char *)malloc(l1+l2+1); + if (!file->name) out_of_memory("receive_file_entry"); + + strncpy(file->name,lastname,l1); + read_buf(f,file->name+l1,l2); + file->name[l1+l2] = 0; + + file->length = (off_t)read_int(f); + file->modtime = (flags & SAME_TIME) ? last_time : (time_t)read_int(f); + file->mode = (flags & SAME_MODE) ? last_mode : (mode_t)read_int(f); + if (preserve_uid) + file->uid = (flags & SAME_UID) ? last_uid : (uid_t)read_int(f); + if (preserve_gid) + file->gid = (flags & SAME_GID) ? last_gid : (gid_t)read_int(f); + if (preserve_devices && IS_DEVICE(file->mode)) + file->dev = (flags & SAME_DEV) ? last_dev : (dev_t)read_int(f); + +#if SUPPORT_LINKS + if (preserve_links && S_ISLNK(file->mode)) { + int l = read_int(f); + file->link = (char *)malloc(l+1); + if (!file->link) out_of_memory("receive_file_entry"); + read_buf(f,file->link,l); + file->link[l] = 0; + } +#endif + + if (always_checksum) + read_buf(f,file->sum,csum_length); + + last_mode = file->mode; + last_dev = file->dev; + last_uid = file->uid; + last_gid = file->gid; + last_time = file->modtime; + + strcpy(lastname,file->name); + lastname[255] = 0; +} + + + static struct file_struct *make_file(int recurse,char *fname) { static struct file_struct file; @@ -299,7 +411,7 @@ struct file_list *send_file_list(int f,int recurse,int argc,char *argv[]) if (dir && *dir) { if (getcwd(dbuf,MAXPATHLEN-1) == NULL) { fprintf(stderr,"getwd : %s\n",strerror(errno)); - exit(1); + exit_cleanup(1); } if (chdir(dir) != 0) { fprintf(stderr,"chdir %s : %s\n",dir,strerror(errno)); @@ -312,7 +424,7 @@ struct file_list *send_file_list(int f,int recurse,int argc,char *argv[]) flist_dir = NULL; if (chdir(dbuf) != 0) { fprintf(stderr,"chdir %s : %s\n",dbuf,strerror(errno)); - exit(1); + exit_cleanup(1); } continue; } @@ -323,7 +435,7 @@ struct file_list *send_file_list(int f,int recurse,int argc,char *argv[]) } if (f != -1) { - write_int(f,0); + send_file_entry(NULL,f); write_flush(f); } @@ -338,8 +450,8 @@ struct file_list *send_file_list(int f,int recurse,int argc,char *argv[]) struct file_list *recv_file_list(int f) { - int l; struct file_list *flist; + unsigned char flags; if (verbose > 2) fprintf(stderr,"recv_file_list starting\n"); @@ -356,7 +468,7 @@ struct file_list *recv_file_list(int f) goto oom; - for (l=read_int(f); l; l=read_int(f)) { + for (flags=read_byte(f); flags; flags=read_byte(f)) { int i = flist->count; if (i >= flist->malloced) { @@ -368,33 +480,7 @@ struct file_list *recv_file_list(int f) goto oom; } - flist->files[i].name = (char *)malloc(l+1); - if (!flist->files[i].name) - goto oom; - - read_buf(f,flist->files[i].name,l); - flist->files[i].name[l] = 0; - flist->files[i].modtime = (time_t)read_int(f); - flist->files[i].length = (off_t)read_int(f); - flist->files[i].mode = (mode_t)read_int(f); - if (preserve_uid) - flist->files[i].uid = (uid_t)read_int(f); - if (preserve_gid) - flist->files[i].gid = (gid_t)read_int(f); - if (preserve_devices) - flist->files[i].dev = (dev_t)read_int(f); - -#if SUPPORT_LINKS - if (preserve_links && S_ISLNK(flist->files[i].mode)) { - int l = read_int(f); - flist->files[i].link = (char *)malloc(l+1); - read_buf(f,flist->files[i].link,l); - flist->files[i].link[l] = 0; - } -#endif - - if (always_checksum) - read_buf(f,flist->files[i].sum,SUM_LENGTH); + receive_file_entry(&flist->files[i],flags,f); if (S_ISREG(flist->files[i].mode)) total_size += flist->files[i].length;