1 /* -*- c-file-style: "linux" -*-
4 Batch utilities for rsync.
11 extern char *batch_name;
12 extern int delete_mode;
13 extern int delete_excluded;
15 static void write_arg(int fd, char *arg)
19 if (*arg == '-' && (x = strchr(arg, '=')) != NULL) {
20 write(fd, arg, x - arg + 1);
24 if (strpbrk(arg, " \"'&;|[]()$#!*?^\\") != NULL) {
26 for (s = arg; (x = strchr(s, '\'')) != NULL; s = x + 1) {
27 write(fd, s, x - s + 1);
30 write(fd, s, strlen(s));
35 write(fd, arg, strlen(arg));
38 /* This routine tries to write out an equivalent --read-batch command
39 * given the user's --write-batch args. However, it doesn't really
40 * understand most of the options, so it uses some overly simple
41 * heuristics to munge the command line into something that will
42 * (hopefully) work. */
43 void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
46 char *p, filename[MAXPATHLEN];
47 int need_excludes = delete_mode && !delete_excluded;
49 stringjoin(filename, sizeof filename,
50 batch_name, ".sh", NULL);
51 fd = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC,
52 S_IRUSR | S_IWUSR | S_IEXEC);
54 rsyserr(FERROR, errno, "Batch file %s open error", filename);
58 /* Write argvs info to BATCH.sh file */
59 write_arg(fd, argv[0]);
60 for (i = 1; i < argc - file_arg_cnt; i++) {
62 if (strncmp(p, "--files-from", 12) == 0
63 || (!need_excludes && (strncmp(p, "--include", 9) == 0
64 || strncmp(p, "--exclude", 9) == 0))) {
65 if (strchr(p, '=') == NULL)
70 if (strncmp(p, "--write-batch", 13) == 0) {
71 write(fd, "--read-batch", 12);
74 write_arg(fd, p + 14);
79 if ((p = find_colon(argv[argc - 1])) != NULL) {
84 write(fd, " ${1:-", 6);
86 if (write(fd, "}\n", 2) != 2 || close(fd) < 0) {
87 rsyserr(FERROR, errno, "Batch file %s write error", filename);
92 void show_flist(int index, struct file_struct **fptr)
94 /* for debugging show_flist(flist->count, flist->files * */
97 for (i = 0; i < index; i++) {
98 rprintf(FINFO, "flist->flags=%#x\n", fptr[i]->flags);
99 rprintf(FINFO, "flist->modtime=%#lx\n",
100 (long unsigned) fptr[i]->modtime);
101 rprintf(FINFO, "flist->length=%.0f\n",
102 (double) fptr[i]->length);
103 rprintf(FINFO, "flist->mode=%#o\n", (int) fptr[i]->mode);
104 rprintf(FINFO, "flist->basename=%s\n", fptr[i]->basename);
105 if (fptr[i]->dirname)
106 rprintf(FINFO, "flist->dirname=%s\n",
108 if (fptr[i]->basedir)
109 rprintf(FINFO, "flist->basedir=%s\n",
114 void show_argvs(int argc, char *argv[])
116 /* for debugging * */
119 rprintf(FINFO, "BATCH.C:show_argvs,argc=%d\n", argc);
120 for (i = 0; i < argc; i++) {
122 rprintf(FINFO, "i=%d,argv[i]=%s\n", i, argv[i]);