Copy the file SRC_NAME to the file DST_NAME aka DST_DIRFD+DST_RELNAME. If NONEXISTENT_DST is positive, DST_NAME does not exist even as a dangling symlink; if negative, it does not exist except possibly as a dangling symlink; if zero, its existence status is unknown. A non-null PARENT describes the parent directory. ANCESTORS points to a linked, null terminated list of devices and
| 1620 | the source was simply renamed to the destination. |
| 1621 | Return true if successful. */ |
| 1622 | static bool |
| 1623 | copy_internal (char const *src_name, char const *dst_name, |
| 1624 | int dst_dirfd, char const *dst_relname, |
| 1625 | int nonexistent_dst, |
| 1626 | struct stat const *parent, |
| 1627 | struct dir_list *ancestors, |
| 1628 | const struct cp_options *x, |
| 1629 | bool command_line_arg, |
| 1630 | bool *first_dir_created_per_command_line_arg, |
| 1631 | bool *copy_into_self, |
| 1632 | bool *rename_succeeded) |
| 1633 | { |
| 1634 | struct stat src_sb; |
| 1635 | struct stat dst_sb; |
| 1636 | mode_t src_mode IF_LINT ( = 0); |
| 1637 | mode_t dst_mode IF_LINT ( = 0); |
| 1638 | mode_t dst_mode_bits; |
| 1639 | mode_t omitted_permissions; |
| 1640 | bool restore_dst_mode = false; |
| 1641 | char *earlier_file = NULL; |
| 1642 | char *dst_backup = NULL; |
| 1643 | char const *drelname = *dst_relname ? dst_relname : "."; |
| 1644 | bool delayed_ok; |
| 1645 | bool copied_as_regular = false; |
| 1646 | bool dest_is_symlink = false; |
| 1647 | bool have_dst_lstat = false; |
| 1648 | |
| 1649 | *copy_into_self = false; |
| 1650 | |
| 1651 | int rename_errno = x->rename_errno; |
| 1652 | if (x->move_mode && !x->exchange) |
| 1653 | { |
| 1654 | if (rename_errno < 0) |
| 1655 | rename_errno = (renameatu (AT_FDCWD, src_name, dst_dirfd, drelname, |
| 1656 | RENAME_NOREPLACE) |
| 1657 | ? errno : 0); |
| 1658 | nonexistent_dst = *rename_succeeded = rename_errno == 0; |
| 1659 | } |
| 1660 | |
| 1661 | if (rename_errno == 0 |
| 1662 | ? !x->last_file |
| 1663 | : rename_errno != EEXIST |
| 1664 | || (x->update != UPDATE_NONE && x->update != UPDATE_NONE_FAIL)) |
| 1665 | { |
| 1666 | char const *name = rename_errno == 0 ? dst_name : src_name; |
| 1667 | int dirfd = rename_errno == 0 ? dst_dirfd : AT_FDCWD; |
| 1668 | char const *relname = rename_errno == 0 ? drelname : src_name; |
| 1669 | int fstatat_flags |
| 1670 | = x->dereference == DEREF_NEVER ? AT_SYMLINK_NOFOLLOW : 0; |
| 1671 | if (follow_fstatat (dirfd, relname, &src_sb, fstatat_flags) != 0) |
| 1672 | { |
| 1673 | error (0, errno, _("cannot stat %s"), quoteaf (name)); |
| 1674 | return false; |
| 1675 | } |
| 1676 | |
| 1677 | src_mode = src_sb.st_mode; |
| 1678 | |
| 1679 | if (S_ISDIR (src_mode) && !x->recursive) |
no test coverage detected