get byte order of checksum seed right
[rsync/rsync.git] / rsync.c
CommitLineData
c627d613
AT
1/*
2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#include "rsync.h"
21
43a481dc
AT
22extern int csum_length;
23
c627d613
AT
24extern int verbose;
25extern int am_server;
26extern int always_checksum;
27extern time_t starttime;
28
29extern char *backup_suffix;
30
31extern int block_size;
32extern int update_only;
33extern int make_backups;
34extern int preserve_links;
dc5ddbcc 35extern int preserve_hard_links;
c627d613
AT
36extern int preserve_perms;
37extern int preserve_devices;
38extern int preserve_uid;
39extern int preserve_gid;
40extern int preserve_times;
41extern int dry_run;
42extern int ignore_times;
43extern int recurse;
44extern int delete_mode;
45extern int cvs_exclude;
46
47/*
48 free a sums struct
49 */
50static void free_sums(struct sum_struct *s)
51{
52 if (s->sums) free(s->sums);
53 free(s);
54}
55
56
57
58/*
59 send a sums struct down a fd
60 */
61static void send_sums(struct sum_struct *s,int f_out)
62{
63 int i;
64
65 /* tell the other guy how many we are going to be doing and how many
66 bytes there are in the last chunk */
67 write_int(f_out,s?s->count:0);
68 write_int(f_out,s?s->n:block_size);
69 write_int(f_out,s?s->remainder:0);
70 if (s)
71 for (i=0;i<s->count;i++) {
72 write_int(f_out,s->sums[i].sum1);
43a481dc 73 write_buf(f_out,s->sums[i].sum2,csum_length);
c627d613
AT
74 }
75 write_flush(f_out);
76}
77
78
79/*
80 generate a stream of signatures/checksums that describe a buffer
81
82 generate approximately one checksum every n bytes
83 */
84static struct sum_struct *generate_sums(char *buf,off_t len,int n)
85{
86 int i;
87 struct sum_struct *s;
88 int count;
89 int block_len = n;
90 int remainder = (len%block_len);
91 off_t offset = 0;
92
93 count = (len+(block_len-1))/block_len;
94
95 s = (struct sum_struct *)malloc(sizeof(*s));
96 if (!s) out_of_memory("generate_sums");
97
98 s->count = count;
99 s->remainder = remainder;
100 s->n = n;
101 s->flength = len;
102
103 if (count==0) {
104 s->sums = NULL;
105 return s;
106 }
107
108 if (verbose > 3)
dc5ddbcc 109 fprintf(FERROR,"count=%d rem=%d n=%d flength=%d\n",
c627d613
AT
110 s->count,s->remainder,s->n,(int)s->flength);
111
112 s->sums = (struct sum_buf *)malloc(sizeof(s->sums[0])*s->count);
113 if (!s->sums) out_of_memory("generate_sums");
114
115 for (i=0;i<count;i++) {
116 int n1 = MIN(len,n);
d9bea2dd 117 char *map = map_ptr(buf,offset,n1);
c627d613 118
d9bea2dd
AT
119 s->sums[i].sum1 = get_checksum1(map,n1);
120 get_checksum2(map,n1,s->sums[i].sum2);
c627d613
AT
121
122 s->sums[i].offset = offset;
123 s->sums[i].len = n1;
124 s->sums[i].i = i;
125
126 if (verbose > 3)
dc5ddbcc 127 fprintf(FERROR,"chunk[%d] offset=%d len=%d sum1=%08x\n",
c627d613
AT
128 i,(int)s->sums[i].offset,s->sums[i].len,s->sums[i].sum1);
129
130 len -= n1;
c627d613
AT
131 offset += n1;
132 }
133
134 return s;
135}
136
137
138/*
139 receive the checksums for a buffer
140 */
141static struct sum_struct *receive_sums(int f)
142{
143 struct sum_struct *s;
144 int i;
145 off_t offset = 0;
146 int block_len;
147
148 s = (struct sum_struct *)malloc(sizeof(*s));
149 if (!s) out_of_memory("receive_sums");
150
151 s->count = read_int(f);
152 s->n = read_int(f);
153 s->remainder = read_int(f);
154 s->sums = NULL;
155
156 if (verbose > 3)
dc5ddbcc 157 fprintf(FERROR,"count=%d n=%d rem=%d\n",
c627d613
AT
158 s->count,s->n,s->remainder);
159
160 block_len = s->n;
161
162 if (s->count == 0)
163 return(s);
164
165 s->sums = (struct sum_buf *)malloc(sizeof(s->sums[0])*s->count);
166 if (!s->sums) out_of_memory("receive_sums");
167
168 for (i=0;i<s->count;i++) {
169 s->sums[i].sum1 = read_int(f);
43a481dc 170 read_buf(f,s->sums[i].sum2,csum_length);
c627d613
AT
171
172 s->sums[i].offset = offset;
173 s->sums[i].i = i;
174
175 if (i == s->count-1 && s->remainder != 0) {
176 s->sums[i].len = s->remainder;
177 } else {
178 s->sums[i].len = s->n;
179 }
180 offset += s->sums[i].len;
181
182 if (verbose > 3)
dc5ddbcc 183 fprintf(FERROR,"chunk[%d] len=%d offset=%d sum1=%08x\n",
c627d613
AT
184 i,s->sums[i].len,(int)s->sums[i].offset,s->sums[i].sum1);
185 }
186
187 s->flength = offset;
188
189 return s;
190}
191
192
193static void set_perms(char *fname,struct file_struct *file,struct stat *st,
194 int report)
195{
196 int updated = 0;
197 struct stat st2;
198
199 if (dry_run) return;
200
201 if (!st) {
202 if (stat(fname,&st2) != 0) {
dc5ddbcc 203 fprintf(FERROR,"stat %s : %s\n",fname,strerror(errno));
c627d613
AT
204 return;
205 }
206 st = &st2;
207 }
208
7bec6a5c
AT
209 if (preserve_times && !S_ISLNK(st->st_mode) &&
210 st->st_mtime != file->modtime) {
c627d613
AT
211 updated = 1;
212 if (set_modtime(fname,file->modtime) != 0) {
dc5ddbcc 213 fprintf(FERROR,"failed to set times on %s : %s\n",
c627d613
AT
214 fname,strerror(errno));
215 return;
216 }
217 }
218
219#ifdef HAVE_CHMOD
7bec6a5c
AT
220 if (preserve_perms && !S_ISLNK(st->st_mode) &&
221 st->st_mode != file->mode) {
c627d613
AT
222 updated = 1;
223 if (chmod(fname,file->mode) != 0) {
dc5ddbcc 224 fprintf(FERROR,"failed to set permissions on %s : %s\n",
c627d613
AT
225 fname,strerror(errno));
226 return;
227 }
228 }
229#endif
230
231 if ((preserve_uid && st->st_uid != file->uid) ||
232 (preserve_gid && st->st_gid != file->gid)) {
233 updated = 1;
234 if (chown(fname,
235 preserve_uid?file->uid:-1,
236 preserve_gid?file->gid:-1) != 0) {
237 if (verbose>1 || preserve_uid)
dc5ddbcc 238 fprintf(FERROR,"chown %s : %s\n",fname,strerror(errno));
c627d613
AT
239 return;
240 }
241 }
242
243 if (verbose > 1 && report) {
244 if (updated)
dc5ddbcc 245 fprintf(FINFO,"%s\n",fname);
c627d613 246 else
dc5ddbcc 247 fprintf(FINFO,"%s is uptodate\n",fname);
c627d613
AT
248 }
249}
250
251
252void recv_generator(char *fname,struct file_list *flist,int i,int f_out)
253{
254 int fd;
255 struct stat st;
256 char *buf;
257 struct sum_struct *s;
258 char sum[SUM_LENGTH];
259 int statret;
dc5ddbcc 260 struct file_struct *file = &flist->files[i];
c627d613
AT
261
262 if (verbose > 2)
dc5ddbcc 263 fprintf(FERROR,"recv_generator(%s)\n",fname);
c627d613
AT
264
265 statret = lstat(fname,&st);
266
267#if SUPPORT_LINKS
dc5ddbcc 268 if (preserve_links && S_ISLNK(file->mode)) {
c627d613
AT
269 char lnk[MAXPATHLEN];
270 int l;
271 if (statret == 0) {
272 l = readlink(fname,lnk,MAXPATHLEN-1);
273 if (l > 0) {
274 lnk[l] = 0;
dc5ddbcc
AT
275 if (strcmp(lnk,file->link) == 0) {
276 set_perms(fname,file,&st,1);
c627d613
AT
277 return;
278 }
279 }
280 }
281 if (!dry_run) unlink(fname);
dc5ddbcc
AT
282 if (!dry_run && symlink(file->link,fname) != 0) {
283 fprintf(FERROR,"link %s -> %s : %s\n",
284 fname,file->link,strerror(errno));
c627d613 285 } else {
dc5ddbcc 286 set_perms(fname,file,NULL,0);
c627d613 287 if (verbose)
dc5ddbcc
AT
288 fprintf(FINFO,"%s -> %s\n",
289 fname,file->link);
c627d613
AT
290 }
291 return;
292 }
293#endif
294
295#ifdef HAVE_MKNOD
dc5ddbcc 296 if (preserve_devices && IS_DEVICE(file->mode)) {
c627d613 297 if (statret != 0 ||
dc5ddbcc
AT
298 st.st_mode != file->mode ||
299 st.st_rdev != file->rdev) {
c627d613
AT
300 if (!dry_run) unlink(fname);
301 if (verbose > 2)
dc5ddbcc
AT
302 fprintf(FERROR,"mknod(%s,0%o,0x%x)\n",
303 fname,(int)file->mode,(int)file->rdev);
c627d613 304 if (!dry_run &&
dc5ddbcc
AT
305 mknod(fname,file->mode,file->rdev) != 0) {
306 fprintf(FERROR,"mknod %s : %s\n",fname,strerror(errno));
c627d613 307 } else {
dc5ddbcc 308 set_perms(fname,file,NULL,0);
c627d613 309 if (verbose)
dc5ddbcc 310 fprintf(FINFO,"%s\n",fname);
c627d613
AT
311 }
312 } else {
dc5ddbcc 313 set_perms(fname,file,&st,1);
c627d613
AT
314 }
315 return;
316 }
317#endif
318
dc5ddbcc
AT
319 if (preserve_hard_links && check_hard_link(file)) {
320 if (verbose > 1)
321 fprintf(FINFO,"%s is a hard link\n",file->name);
322 return;
323 }
324
325 if (!S_ISREG(file->mode)) {
326 fprintf(FERROR,"skipping non-regular file %s\n",fname);
c627d613
AT
327 return;
328 }
329
330 if (statret == -1) {
331 if (errno == ENOENT) {
332 write_int(f_out,i);
333 if (!dry_run) send_sums(NULL,f_out);
334 } else {
335 if (verbose > 1)
dc5ddbcc 336 fprintf(FERROR,"recv_generator failed to open %s\n",fname);
c627d613
AT
337 }
338 return;
339 }
340
341 if (!S_ISREG(st.st_mode)) {
dc5ddbcc 342 fprintf(FERROR,"%s : not a regular file\n",fname);
c627d613
AT
343 return;
344 }
345
dc5ddbcc 346 if (update_only && st.st_mtime >= file->modtime) {
c627d613 347 if (verbose > 1)
dc5ddbcc 348 fprintf(FERROR,"%s is newer\n",fname);
c627d613
AT
349 return;
350 }
351
352 if (always_checksum && S_ISREG(st.st_mode)) {
353 file_checksum(fname,sum,st.st_size);
354 }
355
dc5ddbcc
AT
356 if (st.st_size == file->length &&
357 ((!ignore_times && st.st_mtime == file->modtime) ||
c627d613 358 (always_checksum && S_ISREG(st.st_mode) &&
dc5ddbcc
AT
359 memcmp(sum,file->sum,csum_length) == 0))) {
360 set_perms(fname,file,&st,1);
c627d613
AT
361 return;
362 }
363
364 if (dry_run) {
365 write_int(f_out,i);
366 return;
367 }
368
369 /* open the file */
370 fd = open(fname,O_RDONLY);
371
372 if (fd == -1) {
dc5ddbcc 373 fprintf(FERROR,"failed to open %s : %s\n",fname,strerror(errno));
c627d613
AT
374 return;
375 }
376
377 if (st.st_size > 0) {
378 buf = map_file(fd,st.st_size);
c627d613
AT
379 } else {
380 buf = NULL;
381 }
382
383 if (verbose > 3)
dc5ddbcc 384 fprintf(FERROR,"mapped %s of size %d\n",fname,(int)st.st_size);
c627d613
AT
385
386 s = generate_sums(buf,st.st_size,block_size);
387
388 write_int(f_out,i);
389 send_sums(s,f_out);
390 write_flush(f_out);
391
392 close(fd);
393 unmap_file(buf,st.st_size);
394
395 free_sums(s);
396}
397
398
399
400static void receive_data(int f_in,char *buf,int fd,char *fname)
401{
402 int i,n,remainder,len,count;
403 off_t offset = 0;
404 off_t offset2;
405
406 count = read_int(f_in);
407 n = read_int(f_in);
408 remainder = read_int(f_in);
409
410 for (i=read_int(f_in); i != 0; i=read_int(f_in)) {
411 if (i > 0) {
412 if (verbose > 3)
dc5ddbcc 413 fprintf(FERROR,"data recv %d at %d\n",i,(int)offset);
c627d613
AT
414
415 if (read_write(f_in,fd,i) != i) {
dc5ddbcc 416 fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
34ccb63e 417 exit_cleanup(1);
c627d613
AT
418 }
419 offset += i;
420 } else {
421 i = -(i+1);
422 offset2 = i*n;
423 len = n;
424 if (i == count-1 && remainder != 0)
425 len = remainder;
426
427 if (verbose > 3)
dc5ddbcc 428 fprintf(FERROR,"chunk[%d] of size %d at %d offset=%d\n",
c627d613
AT
429 i,len,(int)offset2,(int)offset);
430
7bec6a5c 431 if (write_sparse(fd,map_ptr(buf,offset2,len),len) != len) {
dc5ddbcc 432 fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
34ccb63e 433 exit_cleanup(1);
c627d613
AT
434 }
435 offset += len;
436 }
437 }
7bec6a5c
AT
438
439 if (offset > 0 && sparse_end(fd) != 0) {
dc5ddbcc 440 fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
34ccb63e 441 exit_cleanup(1);
7bec6a5c 442 }
c627d613
AT
443}
444
445
446static void delete_one(struct file_struct *f)
447{
448 if (!S_ISDIR(f->mode)) {
449 if (!dry_run && unlink(f->name) != 0) {
dc5ddbcc 450 fprintf(FERROR,"unlink %s : %s\n",f->name,strerror(errno));
c627d613 451 } else if (verbose) {
dc5ddbcc 452 fprintf(FERROR,"deleting %s\n",f->name);
c627d613
AT
453 }
454 } else {
455 if (!dry_run && rmdir(f->name) != 0) {
456 if (errno != ENOTEMPTY)
dc5ddbcc 457 fprintf(FERROR,"rmdir %s : %s\n",f->name,strerror(errno));
c627d613 458 } else if (verbose) {
dc5ddbcc 459 fprintf(FERROR,"deleting directory %s\n",f->name);
c627d613
AT
460 }
461 }
462}
463
464
465static void delete_files(struct file_list *flist)
466{
467 struct file_list *local_file_list;
468 char *dot=".";
469 int i;
470
4fe159a8 471 if (cvs_exclude)
79fbb6f5 472 add_cvs_excludes();
4fe159a8 473
c627d613
AT
474 if (!(local_file_list = send_file_list(-1,recurse,1,&dot)))
475 return;
476
477 for (i=local_file_list->count;i>=0;i--) {
478 if (!local_file_list->files[i].name) continue;
479 if (-1 == flist_find(flist,&local_file_list->files[i])) {
480 delete_one(&local_file_list->files[i]);
481 }
482 }
483}
484
485static char *cleanup_fname = NULL;
486
34ccb63e 487void exit_cleanup(int code)
c627d613
AT
488{
489 if (cleanup_fname)
490 unlink(cleanup_fname);
34ccb63e
AT
491 exit(code);
492}
493
494void sig_int(void)
495{
496 exit_cleanup(1);
c627d613
AT
497}
498
499
500int recv_files(int f_in,struct file_list *flist,char *local_name)
501{
502 int fd1,fd2;
503 struct stat st;
504 char *fname;
505 char fnametmp[MAXPATHLEN];
506 char *buf;
507 int i;
dc5ddbcc 508 struct file_struct *file;
c627d613 509
981791bd 510 if (verbose > 2) {
dc5ddbcc 511 fprintf(FERROR,"recv_files(%d) starting\n",flist->count);
981791bd 512 }
c627d613
AT
513
514 if (recurse && delete_mode && !local_name && flist->count>0) {
515 delete_files(flist);
516 }
517
518 while (1)
519 {
520 i = read_int(f_in);
521 if (i == -1) break;
522
dc5ddbcc
AT
523 file = &flist->files[i];
524 fname = file->name;
c627d613
AT
525
526 if (local_name)
527 fname = local_name;
528
529 if (dry_run) {
530 if (!am_server && verbose)
531 printf("%s\n",fname);
532 continue;
533 }
534
535 if (verbose > 2)
dc5ddbcc 536 fprintf(FERROR,"recv_files(%s)\n",fname);
c627d613
AT
537
538 /* open the file */
ac1eb754 539 fd1 = open(fname,O_RDONLY);
c627d613 540
ac1eb754 541 if (fd1 != -1 && fstat(fd1,&st) != 0) {
dc5ddbcc 542 fprintf(FERROR,"fstat %s : %s\n",fname,strerror(errno));
c627d613
AT
543 close(fd1);
544 return -1;
545 }
546
ac1eb754 547 if (fd1 != -1 && !S_ISREG(st.st_mode)) {
dc5ddbcc 548 fprintf(FERROR,"%s : not a regular file\n",fname);
c627d613
AT
549 close(fd1);
550 return -1;
551 }
552
ac1eb754 553 if (fd1 != -1 && st.st_size > 0) {
c627d613 554 buf = map_file(fd1,st.st_size);
c627d613
AT
555 } else {
556 buf = NULL;
557 }
558
559 if (verbose > 2)
dc5ddbcc 560 fprintf(FERROR,"mapped %s of size %d\n",fname,(int)st.st_size);
c627d613
AT
561
562 /* open tmp file */
563 sprintf(fnametmp,"%s.XXXXXX",fname);
564 if (NULL == mktemp(fnametmp)) {
dc5ddbcc 565 fprintf(FERROR,"mktemp %s failed\n",fnametmp);
c627d613
AT
566 return -1;
567 }
dc5ddbcc 568 fd2 = open(fnametmp,O_WRONLY|O_CREAT,file->mode);
c627d613 569 if (fd2 == -1) {
dc5ddbcc 570 fprintf(FERROR,"open %s : %s\n",fnametmp,strerror(errno));
c627d613
AT
571 return -1;
572 }
573
574 cleanup_fname = fnametmp;
575
576 if (!am_server && verbose)
577 printf("%s\n",fname);
578
579 /* recv file data */
580 receive_data(f_in,buf,fd2,fname);
581
981791bd
AT
582 if (fd1 != -1) {
583 unmap_file(buf,st.st_size);
584 close(fd1);
585 }
c627d613
AT
586 close(fd2);
587
588 if (verbose > 2)
dc5ddbcc 589 fprintf(FERROR,"renaming %s to %s\n",fnametmp,fname);
c627d613
AT
590
591 if (make_backups) {
592 char fnamebak[MAXPATHLEN];
593 sprintf(fnamebak,"%s%s",fname,backup_suffix);
ac1eb754 594 if (rename(fname,fnamebak) != 0 && errno != ENOENT) {
dc5ddbcc 595 fprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
34ccb63e 596 exit_cleanup(1);
c627d613
AT
597 }
598 }
599
600 /* move tmp file over real file */
601 if (rename(fnametmp,fname) != 0) {
dc5ddbcc 602 fprintf(FERROR,"rename %s -> %s : %s\n",
c627d613
AT
603 fnametmp,fname,strerror(errno));
604 }
605
606 cleanup_fname = NULL;
607
dc5ddbcc 608 set_perms(fname,file,NULL,0);
c627d613
AT
609 }
610
611 if (verbose > 2)
dc5ddbcc 612 fprintf(FERROR,"recv_files finished\n");
c627d613
AT
613
614 return 0;
615}
616
617
618
619off_t send_files(struct file_list *flist,int f_out,int f_in)
620{
621 int fd;
622 struct sum_struct *s;
623 char *buf;
624 struct stat st;
625 char fname[MAXPATHLEN];
626 off_t total=0;
627 int i;
dc5ddbcc 628 struct file_struct *file;
c627d613
AT
629
630 if (verbose > 2)
dc5ddbcc 631 fprintf(FERROR,"send_files starting\n");
c627d613 632
720b47f2
AT
633 setup_nonblocking(f_in,f_out);
634
c627d613
AT
635 while (1)
636 {
637 i = read_int(f_in);
638 if (i == -1) break;
639
dc5ddbcc
AT
640 file = &flist->files[i];
641
c627d613 642 fname[0] = 0;
dc5ddbcc
AT
643 if (file->dir) {
644 strcpy(fname,file->dir);
c627d613
AT
645 strcat(fname,"/");
646 }
dc5ddbcc 647 strcat(fname,file->name);
c627d613
AT
648
649 if (verbose > 2)
dc5ddbcc 650 fprintf(FERROR,"send_files(%d,%s)\n",i,fname);
c627d613
AT
651
652 if (dry_run) {
653 if (!am_server && verbose)
654 printf("%s\n",fname);
655 write_int(f_out,i);
656 continue;
657 }
658
659 s = receive_sums(f_in);
660 if (!s) {
dc5ddbcc 661 fprintf(FERROR,"receive_sums failed\n");
c627d613
AT
662 return -1;
663 }
664
665 fd = open(fname,O_RDONLY);
666 if (fd == -1) {
dc5ddbcc 667 fprintf(FERROR,"send_files failed to open %s: %s\n",
c627d613
AT
668 fname,strerror(errno));
669 continue;
670 }
671
672 /* map the local file */
673 if (fstat(fd,&st) != 0) {
dc5ddbcc 674 fprintf(FERROR,"fstat failed : %s\n",strerror(errno));
c627d613
AT
675 return -1;
676 }
677
678 if (st.st_size > 0) {
679 buf = map_file(fd,st.st_size);
c627d613
AT
680 } else {
681 buf = NULL;
682 }
683
684 if (verbose > 2)
dc5ddbcc 685 fprintf(FERROR,"send_files mapped %s of size %d\n",
c627d613
AT
686 fname,(int)st.st_size);
687
688 write_int(f_out,i);
689
690 write_int(f_out,s->count);
691 write_int(f_out,s->n);
692 write_int(f_out,s->remainder);
693
694 if (verbose > 2)
dc5ddbcc 695 fprintf(FERROR,"calling match_sums %s\n",fname);
c627d613
AT
696
697 if (!am_server && verbose)
698 printf("%s\n",fname);
699
720b47f2 700 match_sums(f_out,s,buf,st.st_size);
c627d613
AT
701 write_flush(f_out);
702
703 unmap_file(buf,st.st_size);
704 close(fd);
705
706 free_sums(s);
707
708 if (verbose > 2)
dc5ddbcc 709 fprintf(FERROR,"sender finished %s\n",fname);
c627d613
AT
710
711 total += st.st_size;
712 }
713
dc5ddbcc
AT
714 if (verbose > 2)
715 fprintf(FERROR,"send files finished\n");
716
c627d613
AT
717 match_report();
718
719 write_int(f_out,-1);
720 write_flush(f_out);
721
722 return total;
723}
724
725
726
727void generate_files(int f,struct file_list *flist,char *local_name)
728{
729 int i;
730
731 if (verbose > 2)
dc5ddbcc 732 fprintf(FERROR,"generator starting pid=%d count=%d\n",
c627d613
AT
733 (int)getpid(),flist->count);
734
735 for (i = 0; i < flist->count; i++) {
dc5ddbcc
AT
736 struct file_struct *file = &flist->files[i];
737 if (!file->name) continue;
738 if (S_ISDIR(file->mode)) {
c627d613 739 if (dry_run) continue;
dc5ddbcc 740 if (mkdir(file->name,file->mode) != 0 &&
c627d613 741 errno != EEXIST) {
dc5ddbcc
AT
742 fprintf(FERROR,"mkdir %s : %s\n",
743 file->name,strerror(errno));
c627d613
AT
744 }
745 continue;
746 }
dc5ddbcc 747 recv_generator(local_name?local_name:file->name,
c627d613
AT
748 flist,i,f);
749 }
750 write_int(f,-1);
751 write_flush(f);
752 if (verbose > 2)
dc5ddbcc 753 fprintf(FERROR,"generator wrote %d\n",write_total());
c627d613 754}
dc5ddbcc
AT
755
756