Commit | Line | Data |
---|---|---|
08a740ff | 1 | /* -*- c-file-style: "linux" -*- |
71020fc3 | 2 | |
6902ed17 | 3 | Weiss 1/1999 |
08a740ff | 4 | Batch utilities for rsync. |
6902ed17 | 5 | |
1cd5beeb | 6 | */ |
6902ed17 MP |
7 | |
8 | #include "rsync.h" | |
9 | #include <time.h> | |
10 | ||
9b3318b0 | 11 | extern char *batch_name; |
e8d3168e | 12 | |
76f79ba7 | 13 | void write_batch_argvs_file(int argc, char *argv[]) |
6902ed17 | 14 | { |
01966df4 | 15 | int fd, i; |
088aac85 DD |
16 | char filename[MAXPATHLEN]; |
17 | ||
893c4cc0 | 18 | stringjoin(filename, sizeof filename, |
9b3318b0 | 19 | batch_name, ".rsync_argvs", NULL); |
01966df4 WD |
20 | fd = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, |
21 | S_IRUSR | S_IWUSR | S_IEXEC); | |
22 | if (fd < 0) { | |
d62bcc17 | 23 | rsyserr(FERROR, errno, "Batch file %s open error", filename); |
1cd5beeb MP |
24 | exit_cleanup(1); |
25 | } | |
088aac85 | 26 | |
01966df4 WD |
27 | /* Write argvs info to BATCH.rsync_argvs file */ |
28 | for (i = 0; i < argc; i++) { | |
088aac85 | 29 | if (i == argc - 2) /* Skip source directory on cmdline */ |
71020fc3 | 30 | continue; |
b9f592fb WD |
31 | if (strncmp(argv[i], "--files-from=", 13) == 0) |
32 | continue; | |
01966df4 WD |
33 | if (i != 0) |
34 | write(fd, " ", 1); | |
b9f592fb | 35 | if (strncmp(argv[i], "--write-batch=", 14) == 0) { |
01966df4 | 36 | write(fd, "--read-batch=", 13); |
9b3318b0 | 37 | write(fd, batch_name, strlen(batch_name)); |
01966df4 WD |
38 | } else if (i == argc - 1) { |
39 | char *p = find_colon(argv[i]); | |
40 | if (p) { | |
41 | if (*++p == ':') | |
42 | p++; | |
43 | } else | |
44 | p = argv[i]; | |
45 | write(fd, "${1:-", 5); | |
46 | write(fd, p, strlen(p)); | |
47 | write(fd, "}", 1); | |
088aac85 | 48 | } else |
01966df4 | 49 | write(fd, argv[i], strlen(argv[i])); |
1cd5beeb | 50 | } |
01966df4 | 51 | if (write(fd, "\n", 1) != 1 || close(fd) < 0) { |
d62bcc17 | 52 | rsyserr(FERROR, errno, "Batch file %s write error", filename); |
1cd5beeb MP |
53 | exit_cleanup(1); |
54 | } | |
6902ed17 MP |
55 | } |
56 | ||
6902ed17 MP |
57 | void show_flist(int index, struct file_struct **fptr) |
58 | { | |
1cd5beeb MP |
59 | /* for debugging show_flist(flist->count, flist->files * */ |
60 | ||
61 | int i; | |
62 | for (i = 0; i < index; i++) { | |
63 | rprintf(FINFO, "flist->flags=%#x\n", fptr[i]->flags); | |
64 | rprintf(FINFO, "flist->modtime=%#lx\n", | |
65 | (long unsigned) fptr[i]->modtime); | |
66 | rprintf(FINFO, "flist->length=%.0f\n", | |
67 | (double) fptr[i]->length); | |
68 | rprintf(FINFO, "flist->mode=%#o\n", (int) fptr[i]->mode); | |
69 | rprintf(FINFO, "flist->basename=%s\n", fptr[i]->basename); | |
70 | if (fptr[i]->dirname) | |
71 | rprintf(FINFO, "flist->dirname=%s\n", | |
72 | fptr[i]->dirname); | |
73 | if (fptr[i]->basedir) | |
74 | rprintf(FINFO, "flist->basedir=%s\n", | |
75 | fptr[i]->basedir); | |
76 | } | |
6902ed17 MP |
77 | } |
78 | ||
79 | void show_argvs(int argc, char *argv[]) | |
80 | { | |
1cd5beeb | 81 | /* for debugging * */ |
6902ed17 | 82 | |
1cd5beeb MP |
83 | int i; |
84 | rprintf(FINFO, "BATCH.C:show_argvs,argc=%d\n", argc); | |
85 | for (i = 0; i < argc; i++) { | |
86 | /* if (argv[i]) */ | |
87 | rprintf(FINFO, "i=%d,argv[i]=%s\n", i, argv[i]); | |
6902ed17 | 88 | |
1cd5beeb | 89 | } |
6902ed17 | 90 | } |