- int int_str_len;
- char char_str_len[4];
- char buff[256];
- struct file_struct *file;
-
- file = (struct file_struct *)malloc(sizeof(*file));
- if (!file) out_of_memory("read_batch_flist_info");
- memset((char *)file, 0, sizeof(*file));
-
- (*fptr) = file;
-
- read_batch_flist_file((char *)&file->modtime, sizeof(time_t));
- read_batch_flist_file((char *)&file->length, sizeof(OFF_T));
- read_batch_flist_file((char *)&file->mode, sizeof(mode_t));
- read_batch_flist_file((char *)&file->inode, sizeof(INO_T));
- read_batch_flist_file((char *)&file->dev, sizeof(dev_t));
- read_batch_flist_file((char *)&file->rdev, sizeof(dev_t));
- read_batch_flist_file((char *)&file->uid, sizeof(uid_t));
- read_batch_flist_file((char *)&file->gid, sizeof(gid_t));
- read_batch_flist_file(char_str_len, sizeof(char_str_len));
- int_str_len = IVAL(char_str_len,0);
- if (int_str_len > 0) {
- read_batch_flist_file(buff, int_str_len);
- buff[int_str_len] = '\0';
- file->basename = strdup(buff);
- }
- else {
- file->basename = NULL;
- }
-
- read_batch_flist_file(char_str_len, sizeof(char_str_len));
- int_str_len = IVAL(char_str_len,0);
- if (int_str_len > 0) {
- read_batch_flist_file(buff, int_str_len);
- buff[int_str_len] = '\0';
- file[0].dirname = strdup(buff);
- }
- else {
- file[0].dirname = NULL;
- }
-
- read_batch_flist_file(char_str_len, sizeof(char_str_len));
- int_str_len = IVAL(char_str_len,0);
- if (int_str_len > 0) {
- read_batch_flist_file(buff, int_str_len);
- buff[int_str_len] = '\0';
- file[0].basedir = strdup(buff);
- }
- else {
- file[0].basedir = NULL;
- }
-
- read_batch_flist_file(char_str_len, sizeof(char_str_len));
- int_str_len = IVAL(char_str_len,0);
- if (int_str_len > 0) {
- read_batch_flist_file(buff, int_str_len);
- buff[int_str_len] = '\0';
- file[0].link = strdup(buff);
- }
- else {
- file[0].link = NULL;
- }
-
- read_batch_flist_file(char_str_len, sizeof(char_str_len));
- int_str_len = IVAL(char_str_len,0);
- if (int_str_len > 0) {
- read_batch_flist_file(buff, int_str_len);
- buff[int_str_len] = '\0';
- file[0].sum = strdup(buff);
- }
- else {
- file[0].sum = NULL;
- }
-}
-
-void write_batch_csums_file(char *buff, int bytes_to_write)
-{
-
- static int fdb_open = 1;
-
- if (fdb_open) {
- /* Set up file extension */
- strcat(rsync_csums_file, batch_file_ext);
-
- /* Open batch csums file for writing; create it if it doesn't exist */
- fdb = do_open(rsync_csums_file, O_WRONLY|O_CREAT|O_TRUNC,
- S_IREAD|S_IWRITE);
- if (fdb == -1) {
- rprintf(FERROR, "Batch file %s open error: %s\n",
- rsync_csums_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- fdb_open = 0;
- }
-
- /* Write buffer to batch csums file */
-
- if ( write(fdb, buff, bytes_to_write) == -1 ) {
- rprintf(FERROR, "Batch file %s write error: %s\n",
- rsync_csums_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
-}
-
-void close_batch_csums_file()
-{
- close(fdb);
-
-}
-
-void write_batch_csum_info(int *flist_entry, int flist_count, struct sum_struct *s)
-{
- int i;
- int int_zero = 0;
- extern int csum_length;
-
- fdb_open = 1;
-
- /* Write csum info to batch file */
-
- write_batch_csums_file ( (char *) flist_entry, sizeof(int) );
- write_batch_csums_file ( (char *) (s?&s->count:&int_zero), sizeof(int) );
- if (s) {
- for (i=0; i < s->count; i++) {
- write_batch_csums_file( (char *) &s->sums[i].sum1, sizeof(uint32));
- if ( (*flist_entry == flist_count - 1) && (i == s->count - 1) ) {
- fdb_close = 1;
- }
- write_batch_csums_file( s->sums[i].sum2, csum_length);
- }
- }
+ 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;
+ write_batch_csums_file(&int_count, sizeof int_count);
+
+ if (s) {
+ for (i = 0; i < s->count; i++) {
+ write_batch_csums_file(&s->sums[i].sum1, sizeof(uint32));
+ write_batch_csums_file(s->sums[i].sum2, csum_length);
+ }
+ }