-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++) {
- /* FIXME: This apparently crashes if rsync is run with
- * just "rsync -F". I think directly manipulating
- * argv[] is probably bogus -- what if -F is part of a
- * run of several short options? */
- 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);
+extern char *batch_name;
+extern int eol_nulls;
+extern int recurse;
+extern int preserve_links;
+extern int preserve_hard_links;
+extern int preserve_devices;
+extern int preserve_uid;
+extern int preserve_gid;
+extern int always_checksum;
+extern int protocol_version;
+
+extern struct filter_list_struct filter_list;
+
+static int *flag_ptr[] = {
+ &recurse,
+ &preserve_uid,
+ &preserve_gid,
+ &preserve_links,
+ &preserve_devices,
+ &preserve_hard_links,
+ &always_checksum,
+ NULL
+};
+
+static char *flag_name[] = {
+ "--recurse (-r)",
+ "--owner (-o)",
+ "--group (-g)",
+ "--links (-l)",
+ "--devices (-D)",
+ "--hard-links (-H)",
+ "--checksum (-c)",
+ NULL
+};
+
+void write_stream_flags(int fd)
+{
+ int i, flags;
+
+ /* Start the batch file with a bitmap of data-stream-affecting
+ * flags. */
+ for (i = 0, flags = 0; flag_ptr[i]; i++) {
+ if (*flag_ptr[i])
+ flags |= 1 << i;
+ }
+ write_int(fd, flags);
+}
+
+void read_stream_flags(int fd)
+{
+ int i, flags;
+
+ for (i = 0, flags = read_int(fd); flag_ptr[i]; i++) {
+ int set = flags & (1 << i) ? 1 : 0;
+ if (*flag_ptr[i] != set) {
+ if (verbose) {
+ rprintf(FINFO,
+ "%sing the %s option to match the batchfile.\n",
+ set ? "Sett" : "Clear", flag_name[i]);
+ }
+ *flag_ptr[i] = set;