MCPcopy Index your code
hub / github.com/RsyncProject/rsync / write_batch_shell_file

Function write_batch_shell_file

batch.c:255–312  ·  view source on GitHub ↗

This routine tries to write out an equivalent --read-batch command * given the user's --write-batch args. However, it doesn't really * understand most of the options, so it uses some overly simple * heuristics to munge the command line into something that will * (hopefully) work. */

Source from the content-addressed store, hash-verified

253 * heuristics to munge the command line into something that will
254 * (hopefully) work. */
255void write_batch_shell_file(void)
256{
257 int i, j, len, err = 0;
258 char *p, *p2;
259
260 /* Write argvs info to BATCH.sh file */
261 err |= write_arg(raw_argv[0]);
262 if (filter_list.head) {
263 if (protocol_version >= 29)
264 err |= write_opt("--filter", "._-");
265 else
266 err |= write_opt("--exclude-from", "-");
267 }
268
269 /* Elide the filename args from the option list, but scan for them in reverse. */
270 for (i = raw_argc-1, j = cooked_argc-1; i > 0 && j >= 0; i--) {
271 if (strcmp(raw_argv[i], cooked_argv[j]) == 0) {
272 raw_argv[i] = NULL;
273 j--;
274 }
275 }
276
277 for (i = 1; i < raw_argc; i++) {
278 if (!(p = raw_argv[i]))
279 continue;
280 if (strncmp(p, "--files-from", 12) == 0
281 || strncmp(p, "--filter", 8) == 0
282 || strncmp(p, "--include", 9) == 0
283 || strncmp(p, "--exclude", 9) == 0) {
284 if (strchr(p, '=') == NULL)
285 i++;
286 continue;
287 }
288 if (strcmp(p, "-f") == 0) {
289 i++;
290 continue;
291 }
292 if (strncmp(p, "--write-batch", len = 13) == 0
293 || strncmp(p, "--only-write-batch", len = 18) == 0)
294 err |= write_opt("--read-batch", p[len] == '=' ? p + len + 1 : NULL);
295 else {
296 err |= write(batch_sh_fd, " ", 1) != 1;
297 err |= write_arg(p);
298 }
299 }
300 if (!(p = check_for_hostspec(cooked_argv[cooked_argc - 1], &p2, &i)))
301 p = cooked_argv[cooked_argc - 1];
302 err |= write_opt("${1:-", NULL);
303 err |= write_arg(p);
304 err |= write(batch_sh_fd, "}", 1) != 1;
305 if (filter_list.head)
306 write_filter_rules(batch_sh_fd);
307 if (write(batch_sh_fd, "\n", 1) != 1 || close(batch_sh_fd) < 0 || err) {
308 rsyserr(FERROR, errno, "Batch file %s.sh write error", batch_name);
309 exit_cleanup(RERR_FILEIO);
310 }
311 batch_sh_fd = -1;
312}

Callers 1

setup_protocolFunction · 0.85

Calls 5

write_argFunction · 0.85
write_optFunction · 0.85
check_for_hostspecFunction · 0.85
write_filter_rulesFunction · 0.85
rsyserrFunction · 0.70

Tested by

no test coverage detected