X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/a09f6f55da452122cae567cd916ed47a24f790ad..37c817eb8159366539d4a9c69bd78e74d4941c06:/batch.c diff --git a/batch.c b/batch.c index 753eae99..dc96c1df 100644 --- a/batch.c +++ b/batch.c @@ -29,8 +29,8 @@ void write_batch_flist_info(int flist_count, struct file_struct **files) int i, f, save_pv; int64 save_written; - snprintf(filename, sizeof filename, "%s%s", - batch_prefix, rsync_flist_file); + stringjoin(filename, sizeof filename, + batch_prefix, rsync_flist_file, NULL); f = do_open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE); if (f < 0) { @@ -45,9 +45,10 @@ void write_batch_flist_info(int flist_count, struct file_struct **files) 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); + for (i = 0; i < flist_count; i++) { + send_file_entry(files[i], f, files[i]->flags & FLAG_TOP_DIR ? + XMIT_TOP_DIR : 0); + } send_file_entry(NULL, f, 0); protocol_version = save_pv; @@ -65,12 +66,9 @@ void write_batch_argvs_file(int argc, char *argv[]) char buff2[MAXPATHLEN + 6]; char filename[MAXPATHLEN]; - /* Set up file extension */ - strlcpy(filename, batch_prefix, sizeof(filename)); - strlcat(filename, rsync_argvs_file, sizeof(filename)); + stringjoin(filename, sizeof filename, + batch_prefix, rsync_argvs_file, NULL); - /* Open batch argvs file for writing; - * create it if it doesn't exist. */ f = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE | S_IEXEC); if (f < 0) { @@ -128,8 +126,8 @@ struct file_list *create_flist_from_batch(void) int i, f, save_pv; int64 save_read; - snprintf(filename, sizeof filename, "%s%s", - batch_prefix, rsync_flist_file); + stringjoin(filename, sizeof filename, + batch_prefix, rsync_flist_file, NULL); f = do_open(filename, O_RDONLY, 0); if (f < 0) { @@ -153,11 +151,11 @@ struct file_list *create_flist_from_batch(void) out_of_memory("create_flist_from_batch"); for (i = 0; (flags = read_byte(f)) != 0; i++) { - if (protocol_version >= 28 && (flags & EXTENDED_FLAGS)) + if (protocol_version >= 28 && (flags & XMIT_EXTENDED_FLAGS)) 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; @@ -167,25 +165,9 @@ struct file_list *create_flist_from_batch(void) void write_batch_csums_file(void *buff, int bytes_to_write) { - char filename[MAXPATHLEN]; - - if (f_csums < 0) { - strlcpy(filename, batch_prefix, sizeof(filename)); - strlcat(filename, rsync_csums_file, sizeof(filename)); - - f_csums = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, - S_IREAD | S_IWRITE); - if (f_csums < 0) { - rprintf(FERROR, "Batch file %s open error: %s\n", - filename, strerror(errno)); - close(f_csums); - exit_cleanup(1); - } - } - if (write(f_csums, buff, bytes_to_write) < 0) { - rprintf(FERROR, "Batch file %s write error: %s\n", - filename, strerror(errno)); + rprintf(FERROR, "Batch file write error: %s\n", + strerror(errno)); close(f_csums); exit_cleanup(1); } @@ -210,6 +192,21 @@ void write_batch_csum_info(int *flist_entry, struct sum_struct *s) { size_t i; int int_count; + char filename[MAXPATHLEN]; + + if (f_csums < 0) { + stringjoin(filename, sizeof filename, + batch_prefix, rsync_csums_file, NULL); + + f_csums = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, + S_IREAD | S_IWRITE); + if (f_csums < 0) { + rprintf(FERROR, "Batch file %s open error: %s\n", + filename, strerror(errno)); + close(f_csums); + exit_cleanup(1); + } + } write_batch_csums_file(flist_entry, sizeof(int)); int_count = s ? (int) s->count : 0; @@ -226,29 +223,13 @@ void write_batch_csum_info(int *flist_entry, struct sum_struct *s) int read_batch_csums_file(char *buff, int len) { int bytes_read; - char filename[MAXPATHLEN]; - - if (f_csums < 0) { - strlcpy(filename, batch_prefix, sizeof(filename)); - strlcat(filename, rsync_csums_file, sizeof(filename)); - f_csums = do_open(filename, O_RDONLY, 0); - if (f_csums < 0) { - rprintf(FERROR, "Batch file %s open error: %s\n", - filename, strerror(errno)); - close(f_csums); - exit_cleanup(1); - } - } - - bytes_read = read(f_csums, buff, len); - if (bytes_read < 0) { - rprintf(FERROR, "Batch file %s read error: %s\n", - filename, strerror(errno)); + if ((bytes_read = read(f_csums, buff, len)) < 0) { + rprintf(FERROR, "Batch file read error: %s\n", + strerror(errno)); close(f_csums); exit_cleanup(1); } - return bytes_read; } @@ -260,6 +241,20 @@ void read_batch_csum_info(int flist_entry, struct sum_struct *s, int file_chunk_ct; uint32 file_sum1; char file_sum2[SUM_LENGTH]; + char filename[MAXPATHLEN]; + + if (f_csums < 0) { + stringjoin(filename, sizeof filename, + batch_prefix, rsync_csums_file, NULL); + + f_csums = do_open(filename, O_RDONLY, 0); + if (f_csums < 0) { + rprintf(FERROR, "Batch file %s open error: %s\n", + filename, strerror(errno)); + close(f_csums); + exit_cleanup(1); + } + } read_batch_csums_file((char *) &file_flist_entry, sizeof(int)); if (file_flist_entry != flist_entry) { @@ -273,7 +268,6 @@ void read_batch_csum_info(int flist_entry, struct sum_struct *s, sizeof(int)); *checksums_match = 1; for (i = 0; i < file_chunk_ct; i++) { - read_batch_csums_file((char *) &file_sum1, sizeof(uint32)); read_batch_csums_file(file_sum2, csum_length); @@ -292,8 +286,8 @@ void write_batch_delta_file(char *buff, int bytes_to_write) char filename[MAXPATHLEN]; if (f_delta < 0) { - strlcpy(filename, batch_prefix, sizeof(filename)); - strlcat(filename, rsync_delta_file, sizeof(filename)); + stringjoin(filename, sizeof filename, + batch_prefix, rsync_delta_file, NULL); f_delta = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); @@ -324,8 +318,8 @@ int read_batch_delta_file(char *buff, int len) char filename[MAXPATHLEN]; if (f_delta < 0) { - strlcpy(filename, batch_prefix, sizeof(filename)); - strlcat(filename, rsync_delta_file, sizeof(filename)); + stringjoin(filename, sizeof filename, + batch_prefix, rsync_delta_file, NULL); f_delta = do_open(filename, O_RDONLY, 0); if (f_delta < 0) {