| 377 | Return true if successful. */ |
| 378 | |
| 379 | static bool |
| 380 | copy_dir (char const *src_name_in, char const *dst_name_in, |
| 381 | int dst_dirfd, char const *dst_relname_in, bool new_dst, |
| 382 | const struct stat *src_sb, struct dir_list *ancestors, |
| 383 | const struct cp_options *x, |
| 384 | bool *first_dir_created_per_command_line_arg, |
| 385 | bool *copy_into_self) |
| 386 | { |
| 387 | char *name_space; |
| 388 | char *namep; |
| 389 | struct cp_options non_command_line_options = *x; |
| 390 | bool ok = true; |
| 391 | |
| 392 | name_space = savedir (src_name_in, SAVEDIR_SORT_FASTREAD); |
| 393 | if (name_space == NULL) |
| 394 | { |
| 395 | /* This diagnostic is a bit vague because savedir can fail in |
| 396 | several different ways. */ |
| 397 | error (0, errno, _("cannot access %s"), quoteaf (src_name_in)); |
| 398 | return false; |
| 399 | } |
| 400 | |
| 401 | /* For cp's -H option, dereference command line arguments, but do not |
| 402 | dereference symlinks that are found via recursive traversal. */ |
| 403 | if (x->dereference == DEREF_COMMAND_LINE_ARGUMENTS) |
| 404 | non_command_line_options.dereference = DEREF_NEVER; |
| 405 | |
| 406 | bool new_first_dir_created = false; |
| 407 | namep = name_space; |
| 408 | while (*namep != '\0') |
| 409 | { |
| 410 | bool local_copy_into_self; |
| 411 | char *src_name = file_name_concat (src_name_in, namep, NULL); |
| 412 | char *dst_name = file_name_concat (dst_name_in, namep, NULL); |
| 413 | bool first_dir_created = *first_dir_created_per_command_line_arg; |
| 414 | bool rename_succeeded; |
| 415 | |
| 416 | ok &= copy_internal (src_name, dst_name, dst_dirfd, |
| 417 | dst_name + (dst_relname_in - dst_name_in), |
| 418 | new_dst, src_sb, |
| 419 | ancestors, &non_command_line_options, false, |
| 420 | &first_dir_created, |
| 421 | &local_copy_into_self, &rename_succeeded); |
| 422 | *copy_into_self |= local_copy_into_self; |
| 423 | |
| 424 | free (dst_name); |
| 425 | free (src_name); |
| 426 | |
| 427 | /* If we're copying into self, there's no point in continuing, |
| 428 | and in fact, that would even infloop, now that we record only |
| 429 | the first created directory per command line argument. */ |
| 430 | if (local_copy_into_self) |
| 431 | break; |
| 432 | |
| 433 | new_first_dir_created |= first_dir_created; |
| 434 | namep += strlen (namep) + 1; |
| 435 | } |
| 436 | free (name_space); |
no test coverage detected