Commit 76f79ba7 authored by Martin Pool's avatar Martin Pool

Patch from Jos Backus -- Fix breakage from dev_t to DEV64_T in batch

mode.

Also, drop -f and -F for batch mode: these should be reserved for
options that are more commonly used.

It also appends a newline to the argvs file and skips adding the
source directory to the command line.
parent 9dd891bb
...@@ -35,6 +35,7 @@ void create_batch_file_ext() ...@@ -35,6 +35,7 @@ void create_batch_file_ext()
timeptr->tm_year + 1900, timeptr->tm_mon + 1, timeptr->tm_year + 1900, timeptr->tm_mon + 1,
timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min,
timeptr->tm_sec); timeptr->tm_sec);
rprintf(FINFO,"batch file extension: %s\n", batch_file_ext);
} }
void set_batch_file_ext(char *ext) void set_batch_file_ext(char *ext)
...@@ -84,12 +85,16 @@ void write_batch_flist_info(int flist_count, struct file_struct **fptr) ...@@ -84,12 +85,16 @@ void write_batch_flist_info(int flist_count, struct file_struct **fptr)
/* Write flist info to batch file */ /* Write flist info to batch file */
bytes_to_write = sizeof(unsigned) + bytes_to_write =
sizeof(unsigned) +
sizeof(time_t) + sizeof(time_t) +
sizeof(OFF_T) + sizeof(OFF_T) +
sizeof(mode_t) + sizeof(mode_t) +
sizeof(INO64_T) + sizeof(INO64_T) +
(2 * sizeof(DEV64_T)) + sizeof(uid_t) + sizeof(gid_t); sizeof(DEV64_T) +
sizeof(DEV64_T) +
sizeof(uid_t) +
sizeof(gid_t);
fdb_open = 1; fdb_open = 1;
fdb_close = 0; fdb_close = 0;
...@@ -128,7 +133,7 @@ void write_char_bufs(char *buf) ...@@ -128,7 +133,7 @@ void write_char_bufs(char *buf)
} }
} }
void write_batch_argvs_file(int orig_argc, int argc, char **argv) void write_batch_argvs_file(int argc, char *argv[])
{ {
int fdb; int fdb;
int i; int i;
...@@ -149,23 +154,27 @@ void write_batch_argvs_file(int orig_argc, int argc, char **argv) ...@@ -149,23 +154,27 @@ void write_batch_argvs_file(int orig_argc, int argc, char **argv)
buff[0] = '\0'; buff[0] = '\0';
/* Write argvs info to batch file */ /* Write argvs info to batch file */
for (i = argc - orig_argc; i < argc; i++) { for (i = 0; i < argc; ++i) {
/* FIXME: This apparently crashes if rsync is run with if (i == argc - 2)
* just "rsync -F". I think directly manipulating continue;
* argv[] is probably bogus -- what if -F is part of a /*
* run of several short options? */ * FIXME:
if (!strcmp(argv[i], "-F")) { /* safer to change it here than script */ * I think directly manipulating argv[] is probably bogus
strncat(buff, "-f ", 3); /* chg to -f + ext to get ready for remote */ */
strncat(buff, batch_file_ext, if (!strcmp(argv[i], "--write-batch")) {
strlen(batch_file_ext)); /* Safer to change it here than script */
/* Change to --read-batch + ext * to get ready for remote */
strlcat(buff, "--read-batch ", sizeof(buff));
strlcat(buff, batch_file_ext, sizeof(buff));
} else { } else {
strncat(buff, argv[i], strlen(argv[i])); strlcat(buff, argv[i], sizeof(buff));
} }
if (i < (argc - 1)) { if (i < (argc - 1)) {
strncat(buff, " ", 1); strlcat(buff, " ", sizeof(buff));
} }
} }
strlcat(buff, "\n", sizeof(buff));
if (!write(fdb, buff, strlen(buff))) { if (!write(fdb, buff, strlen(buff))) {
rprintf(FERROR, "Batch file %s write error: %s\n", rprintf(FERROR, "Batch file %s write error: %s\n",
rsync_argvs_file, strerror(errno)); rsync_argvs_file, strerror(errno));
...@@ -291,7 +300,7 @@ void read_batch_flist_info(struct file_struct **fptr) ...@@ -291,7 +300,7 @@ void read_batch_flist_info(struct file_struct **fptr)
read_batch_flist_file((char *) &file->mode, sizeof(mode_t)); read_batch_flist_file((char *) &file->mode, sizeof(mode_t));
read_batch_flist_file((char *) &file->inode, sizeof(INO64_T)); read_batch_flist_file((char *) &file->inode, sizeof(INO64_T));
read_batch_flist_file((char *) &file->dev, sizeof(DEV64_T)); read_batch_flist_file((char *) &file->dev, sizeof(DEV64_T));
read_batch_flist_file((char *) &file->rdev, sizeof(dev_t)); read_batch_flist_file((char *) &file->rdev, sizeof(DEV64_T));
read_batch_flist_file((char *) &file->uid, sizeof(uid_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 *) &file->gid, sizeof(gid_t));
read_batch_flist_file(char_str_len, sizeof(char_str_len)); read_batch_flist_file(char_str_len, sizeof(char_str_len));
......
...@@ -803,8 +803,10 @@ int main(int argc,char *argv[]) ...@@ -803,8 +803,10 @@ int main(int argc,char *argv[])
extern int write_batch; /* dw */ extern int write_batch; /* dw */
extern char *batch_ext; /* dw */ extern char *batch_ext; /* dw */
int orig_argc; /* dw */ int orig_argc; /* dw */
char **orig_argv;
orig_argc = argc; /* dw */ orig_argc = argc; /* dw */
orig_argv = argv;
signal(SIGUSR1, sigusr1_handler); signal(SIGUSR1, sigusr1_handler);
signal(SIGUSR2, sigusr2_handler); signal(SIGUSR2, sigusr2_handler);
...@@ -844,7 +846,7 @@ int main(int argc,char *argv[]) ...@@ -844,7 +846,7 @@ int main(int argc,char *argv[])
if (write_batch) { /* dw */ if (write_batch) { /* dw */
create_batch_file_ext(); create_batch_file_ext();
write_batch_argvs_file(orig_argc, argc, argv); write_batch_argvs_file(orig_argc, orig_argv);
} }
if (read_batch) { /* dw */ if (read_batch) { /* dw */
......
...@@ -240,8 +240,8 @@ void usage(enum logcode F) ...@@ -240,8 +240,8 @@ void usage(enum logcode F)
rprintf(F," --log-format=FORMAT log file transfers using specified format\n"); rprintf(F," --log-format=FORMAT log file transfers using specified format\n");
rprintf(F," --password-file=FILE get password from FILE\n"); rprintf(F," --password-file=FILE get password from FILE\n");
rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n"); rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n");
rprintf(F," -f --read-batch=EXT read batch file\n"); rprintf(F," --read-batch=EXT read batch file\n");
rprintf(F," -F --write-batch write batch file\n"); rprintf(F," --write-batch write batch file\n");
rprintf(F," -h, --help show this help screen\n"); rprintf(F," -h, --help show this help screen\n");
#ifdef INET6 #ifdef INET6
rprintf(F," -4 prefer IPv4\n"); rprintf(F," -4 prefer IPv4\n");
...@@ -262,7 +262,7 @@ enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE, ...@@ -262,7 +262,7 @@ enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS, OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR,
OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO, OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
OPT_MODIFY_WINDOW}; OPT_MODIFY_WINDOW, OPT_READ_BATCH, OPT_WRITE_BATCH};
static struct poptOption long_options[] = { static struct poptOption long_options[] = {
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
...@@ -331,8 +331,8 @@ static struct poptOption long_options[] = { ...@@ -331,8 +331,8 @@ static struct poptOption long_options[] = {
{"address", 0, POPT_ARG_STRING, &bind_address, 0}, {"address", 0, POPT_ARG_STRING, &bind_address, 0},
{"backup-dir", 0, POPT_ARG_STRING, &backup_dir}, {"backup-dir", 0, POPT_ARG_STRING, &backup_dir},
{"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links}, {"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links},
{"read-batch", 'f', POPT_ARG_STRING, &batch_ext, 'f'}, {"read-batch", 0, POPT_ARG_STRING, &batch_ext, OPT_READ_BATCH},
{"write-batch", 'F', POPT_ARG_NONE, &write_batch, 0}, {"write-batch", 0, POPT_ARG_NONE, &write_batch},
#ifdef INET6 #ifdef INET6
{0, '4', POPT_ARG_VAL, &default_af_hint, AF_INET }, {0, '4', POPT_ARG_VAL, &default_af_hint, AF_INET },
{0, '6', POPT_ARG_VAL, &default_af_hint, AF_INET6 }, {0, '6', POPT_ARG_VAL, &default_af_hint, AF_INET6 },
...@@ -511,9 +511,8 @@ int parse_arguments(int *argc, const char ***argv, int frommain) ...@@ -511,9 +511,8 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
keep_partial = 1; keep_partial = 1;
break; break;
case OPT_READ_BATCH:
case 'f': /* The filename is stored in batch_ext for us by popt */
/* The filename is stored for us by popt */
read_batch = 1; read_batch = 1;
break; break;
...@@ -550,7 +549,8 @@ void server_options(char **args,int *argc) ...@@ -550,7 +549,8 @@ void server_options(char **args,int *argc)
static char mdelete[30]; static char mdelete[30];
static char mwindow[30]; static char mwindow[30];
static char bw[50]; static char bw[50];
static char fext[20]; /* dw */ static char fext[20];
static char wbatch[14];
int i, x; int i, x;
...@@ -605,8 +605,6 @@ void server_options(char **args,int *argc) ...@@ -605,8 +605,6 @@ void server_options(char **args,int *argc)
argstr[x++] = 'S'; argstr[x++] = 'S';
if (do_compression) if (do_compression)
argstr[x++] = 'z'; argstr[x++] = 'z';
if (write_batch)
argstr[x++] = 'F'; /* dw */
/* this is a complete hack - blame Rusty /* this is a complete hack - blame Rusty
...@@ -629,8 +627,13 @@ void server_options(char **args,int *argc) ...@@ -629,8 +627,13 @@ void server_options(char **args,int *argc)
args[ac++] = mdelete; args[ac++] = mdelete;
} }
if (write_batch) {
snprintf(wbatch,sizeof(wbatch),"--write-batch");
args[ac++] = wbatch;
}
if (batch_ext != NULL) { if (batch_ext != NULL) {
sprintf(fext,"-f%s",batch_ext); snprintf(fext,sizeof(fext),"--read-batch=%s",batch_ext);
args[ac++] = fext; args[ac++] = fext;
} }
......
...@@ -277,8 +277,8 @@ verb( ...@@ -277,8 +277,8 @@ verb(
--log-format=FORMAT log file transfers using specified format --log-format=FORMAT log file transfers using specified format
--password-file=FILE get password from FILE --password-file=FILE get password from FILE
--bwlimit=KBPS limit I/O bandwidth, KBytes per second --bwlimit=KBPS limit I/O bandwidth, KBytes per second
-f, --read-batch=FILE read batch file --read-batch=FILE read batch file
-F, --write-batch write batch file --write-batch write batch file
-h, --help show this help screen -h, --help show this help screen
...@@ -798,7 +798,7 @@ for synchronizing the contents of bf(target_dir) with the updates found in ...@@ -798,7 +798,7 @@ for synchronizing the contents of bf(target_dir) with the updates found in
bf(src_dir) bf(src_dir)
quote( quote(
$ rsync -F [other rsync options here] \nl() $ rsync --write-batch [other rsync options here] \nl()
/somewhere/src_dir /somewhere/target_dir /somewhere/src_dir /somewhere/target_dir
) )
......
...@@ -159,13 +159,14 @@ void send_files(struct file_list *flist,int f_out,int f_in) ...@@ -159,13 +159,14 @@ void send_files(struct file_list *flist,int f_out,int f_in)
initial_stats = stats; initial_stats = stats;
s = receive_sums(f_in); s = receive_sums(f_in);
if (write_batch) /* dw */
write_batch_csum_info(&i,flist->count,s);
if (!s) { if (!s) {
io_error = 1; io_error = 1;
rprintf(FERROR,"receive_sums failed\n"); rprintf(FERROR,"receive_sums failed\n");
return; return;
} }
if (write_batch)
write_batch_csum_info(&i,flist->count,s);
if (!read_batch) { if (!read_batch) {
fd = do_open(fname, O_RDONLY, 0); fd = do_open(fname, O_RDONLY, 0);
......
...@@ -173,10 +173,7 @@ pid_t local_child(int argc, char **argv,int *f_in,int *f_out) ...@@ -173,10 +173,7 @@ pid_t local_child(int argc, char **argv,int *f_in,int *f_out)
extern int am_sender; extern int am_sender;
extern int am_server; extern int am_server;
if (read_batch) am_sender = read_batch ? 0 : !am_sender;
am_sender = 0;
else
am_sender = !am_sender;
am_server = 1; am_server = 1;
if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 || if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment