| 726 | to give it slightly more up-to-date contents. */ |
| 727 | |
| 728 | static bool |
| 729 | copy_reg (char const *src_name, char const *dst_name, |
| 730 | int dst_dirfd, char const *dst_relname, |
| 731 | const struct cp_options *x, |
| 732 | mode_t dst_mode, mode_t omitted_permissions, bool *new_dst, |
| 733 | struct stat *src_sb) |
| 734 | { |
| 735 | int dest_desc; |
| 736 | int dest_errno; |
| 737 | int source_desc; |
| 738 | mode_t extra_permissions; |
| 739 | struct stat sb; |
| 740 | struct stat src_open_sb; |
| 741 | bool return_val = true; |
| 742 | bool data_copy_required = x->data_copy_required; |
| 743 | bool preserve_xattr = USE_XATTR & x->preserve_xattr; |
| 744 | |
| 745 | copy_debug.offload = COPY_DEBUG_UNKNOWN; |
| 746 | copy_debug.reflink = x->reflink_mode ? COPY_DEBUG_UNKNOWN : COPY_DEBUG_NO; |
| 747 | copy_debug.sparse_detection = COPY_DEBUG_UNKNOWN; |
| 748 | |
| 749 | source_desc = open (src_name, |
| 750 | (O_RDONLY | O_BINARY |
| 751 | | (x->dereference == DEREF_NEVER ? O_NOFOLLOW : 0))); |
| 752 | if (source_desc < 0) |
| 753 | { |
| 754 | error (0, errno, _("cannot open %s for reading"), quoteaf (src_name)); |
| 755 | return false; |
| 756 | } |
| 757 | |
| 758 | if (fstat (source_desc, &src_open_sb) != 0) |
| 759 | { |
| 760 | error (0, errno, _("cannot fstat %s"), quoteaf (src_name)); |
| 761 | return_val = false; |
| 762 | goto close_src_desc; |
| 763 | } |
| 764 | |
| 765 | /* Compare the source dev/ino from the open file to the incoming, |
| 766 | saved ones obtained via a previous call to stat. */ |
| 767 | if (! psame_inode (src_sb, &src_open_sb)) |
| 768 | { |
| 769 | error (0, 0, |
| 770 | _("skipping file %s, as it was replaced while being copied"), |
| 771 | quoteaf (src_name)); |
| 772 | return_val = false; |
| 773 | goto close_src_desc; |
| 774 | } |
| 775 | |
| 776 | /* Might as well tell the caller about the latest version of the |
| 777 | source file status, since we have it already. */ |
| 778 | *src_sb = src_open_sb; |
| 779 | mode_t src_mode = src_sb->st_mode; |
| 780 | |
| 781 | /* The semantics of the following open calls are mandated |
| 782 | by the specs for both cp and mv. */ |
| 783 | if (! *new_dst) |
| 784 | { |
| 785 | int open_flags = |
no test coverage detected