-char rsync_flist_file[27] = "rsync_flist.";
-char rsync_csums_file[27] = "rsync_csums.";
-char rsync_delta_file[27] = "rsync_delta.";
-char rsync_argvs_file[27] = "rsync_argvs.";
-
-char batch_file_ext[15];
-
-int fdb;
-int fdb_delta;
-int fdb_open;
-int fdb_close;
-
-struct file_list *batch_flist;
-
-void create_batch_file_ext()
-{
- struct tm *timeptr;
- time_t elapsed_seconds;
-
- /* Save run date and time to use for batch file extensions */
- time(&elapsed_seconds);
- timeptr = localtime(&elapsed_seconds);
-
- sprintf(batch_file_ext, "%4d%02d%02d%02d%02d%02d",
- timeptr->tm_year+1900, timeptr->tm_mon+1, timeptr->tm_mday,
- timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
-}
-
-void set_batch_file_ext(char *ext)
-{
- strcpy(batch_file_ext, ext);
-}
-
-void write_batch_flist_file(char *buff, int bytes_to_write)
-{
-
- if (fdb_open) {
- /* Set up file extension */
- strcat(rsync_flist_file, batch_file_ext);
-
- /* Open batch flist file for writing; create it if it doesn't exist */
- fdb = do_open(rsync_flist_file, O_WRONLY|O_CREAT|O_TRUNC,
- S_IREAD|S_IWRITE);
- if (fdb == -1) {
- rprintf(FERROR, "Batch file %s open error: %s\n",
- rsync_flist_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- fdb_open = 0;
- }
-
- /* Write buffer to batch flist file */
-
- if ( write(fdb, buff, bytes_to_write) == -1 ) {
- rprintf(FERROR, "Batch file %s write error: %s\n",
- rsync_flist_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
-
-
- if (fdb_close) {
- close(fdb);
- }
-}
-
-void write_batch_flist_info(int flist_count, struct file_struct **fptr)
-{
- int i;
- int bytes_to_write;
-
- /* Write flist info to batch file */
-
- bytes_to_write = sizeof(unsigned) +
- sizeof(time_t) +
- sizeof(OFF_T) +
- sizeof(mode_t) +
- sizeof(INO_T) +
- (2 * sizeof(dev_t)) +
- sizeof(uid_t) +
- sizeof(gid_t);
-
- fdb_open = 1;
- fdb_close = 0;
-
- for (i=0; i<flist_count; i++) {
- write_batch_flist_file( (char *) fptr[i], bytes_to_write);
- write_char_bufs(fptr[i]->basename);
- write_char_bufs(fptr[i]->dirname);
- write_char_bufs(fptr[i]->basedir);
- write_char_bufs(fptr[i]->link);
- if (i==flist_count - 1) {
- fdb_close = 1;
- }
- write_char_bufs(fptr[i]->sum);
- }
-
-}
-
-void write_char_bufs(char *buf)
-{
- /* Write the size of the string which will follow */
-
- char b[4];
- if (buf != NULL)
- SIVAL(b,0,strlen(buf));
- else {
- SIVAL(b,0,0);
- }
-
- write_batch_flist_file(b, sizeof(int));
-
- /* Write the string if there is one */
-
- if (buf != NULL) {
- write_batch_flist_file(buf, strlen(buf));
- }
-}
-
-void write_batch_argvs_file(int orig_argc, int argc, char **argv)
-{
- int fdb;
- int i;
- char buff[256];
-
- strcat(rsync_argvs_file, batch_file_ext);
-
-
- /* Open batch argvs file for writing; create it if it doesn't exist */
- fdb = do_open(rsync_argvs_file, O_WRONLY|O_CREAT|O_TRUNC,
- S_IREAD|S_IWRITE|S_IEXEC);
- if (fdb == -1) {
- rprintf(FERROR, "Batch file %s open error: %s\n", rsync_argvs_file,
- strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- buff[0] = '\0';
- /* Write argvs info to batch file */
-
- for (i=argc - orig_argc;i<argc;i++) {
- if ( !strcmp(argv[i],"-F") ){ /* safer to change it here than script*/
- strncat(buff,"-f ",3); /* chg to -f + ext to get ready for remote */
- strncat(buff,batch_file_ext,strlen(batch_file_ext));
- }
- else {
- strncat(buff,argv[i],strlen(argv[i]));
- }
-
- if (i < (argc - 1)) {
- strncat(buff," ",1);
- }
- }
- if (!write(fdb, buff, strlen(buff))) {
- rprintf(FERROR, "Batch file %s write error: %s\n",
- rsync_argvs_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- close(fdb);
-}
-
-struct file_list *create_flist_from_batch()
-{
- unsigned char flags;
-
- fdb_open = 1;
- fdb_close = 0;
-
- batch_flist = (struct file_list *)malloc(sizeof(batch_flist[0]));
- if (!batch_flist) {
- out_of_memory("create_flist_from_batch");
- }
- batch_flist->count=0;
- batch_flist->malloced=1000;
- batch_flist->files = (struct file_struct **)malloc(sizeof(batch_flist->files[0])* batch_flist->malloced);
- if (!batch_flist->files) {
- out_of_memory("create_flist_from_batch"); /* dw -- will exit */
- }
-
- for ( flags=read_batch_flags() ; flags; flags=read_batch_flags() ) {
-
- int i = batch_flist->count;
-
- if (i >= batch_flist->malloced) {
- if (batch_flist->malloced < 1000)
- batch_flist->malloced += 1000;
- else
- batch_flist->malloced *= 2;
- batch_flist->files =(struct file_struct **)realloc(batch_flist->files,
- sizeof(batch_flist->files[0])*
- batch_flist->malloced);
- if (!batch_flist->files)
- out_of_memory("create_flist_from_batch");
- }
- read_batch_flist_info(&batch_flist->files[i]);
- batch_flist->files[i]->flags = flags;
-
- batch_flist->count++;
- }
-
- return batch_flist;
-
-}
-
-int read_batch_flist_file(char *buff, int len)
-{
- int bytes_read;
-
- if (fdb_open) {
-
- /* Set up file extension */
- strcat(rsync_flist_file, batch_file_ext);
-
- /* Open batch flist file for reading */
- fdb = do_open(rsync_flist_file, O_RDONLY, 0);
- if (fdb == -1) {
- rprintf(FERROR, "Batch file %s open error: %s\n", rsync_flist_file,
- strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- fdb_open = 0;
- }
-
- /* Read flist batch file */
-
- bytes_read = read(fdb, buff, len);
-
- if (bytes_read == -1) {
- rprintf(FERROR, "Batch file %s read error: %s\n",
- rsync_flist_file, strerror(errno));
- close(fdb);
- exit_cleanup(1);
- }
- if (bytes_read == 0) { /* EOF */
- close(fdb);
- }
- return bytes_read;
-}
-
-unsigned char read_batch_flags()
-{
- int flags;
-
- if (read_batch_flist_file((char *)&flags, 4) ) {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-void read_batch_flist_info(struct file_struct **fptr)
+extern int eol_nulls;
+extern int recurse;
+extern int xfer_dirs;
+extern int preserve_links;
+extern int preserve_hard_links;
+extern int preserve_devices;
+extern int preserve_uid;
+extern int preserve_gid;
+extern int preserve_acls;
+extern int preserve_xattrs;
+extern int always_checksum;
+extern int do_compression;
+extern int def_compress_level;
+extern int inplace;
+extern int append_mode;
+extern int protocol_version;
+extern char *batch_name;
+#ifdef ICONV_OPTION
+extern char *iconv_opt;
+#endif
+
+extern struct filter_list_struct filter_list;
+
+static int tweaked_compress_level;
+static int tweaked_append;
+static int tweaked_append_verify;
+static int tweaked_iconv;
+
+static int *flag_ptr[] = {
+ &recurse, /* 0 */
+ &preserve_uid, /* 1 */
+ &preserve_gid, /* 2 */
+ &preserve_links, /* 3 */
+ &preserve_devices, /* 4 */
+ &preserve_hard_links, /* 5 */
+ &always_checksum, /* 6 */
+ &xfer_dirs, /* 7 (protocol 29) */
+ &tweaked_compress_level,/* 8 (protocol 29) */
+ &tweaked_iconv, /* 9 (protocol 30) */
+ &preserve_acls, /* 10 (protocol 30) */
+ &preserve_xattrs, /* 11 (protocol 30) */
+ &inplace, /* 12 (protocol 30) */
+ &tweaked_append, /* 13 (protocol 30) */
+ &tweaked_append_verify, /* 14 (protocol 30) */
+ NULL
+};
+
+static char *flag_name[] = {
+ "--recurse (-r)",
+ "--owner (-o)",
+ "--group (-g)",
+ "--links (-l)",
+ "--devices (-D)",
+ "--hard-links (-H)",
+ "--checksum (-c)",
+ "--dirs (-d)",
+ "--compress (-z)",
+ "--iconv",
+ "--acls (-A)",
+ "--xattrs (-X)",
+ "--inplace",
+ "--append",
+ "--append-verify",
+ NULL
+};
+
+void write_stream_flags(int fd)