MCPcopy Create free account
hub / github.com/coreutils/coreutils / copy_reg

Function copy_reg

src/copy.c:728–1150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

726 to give it slightly more up-to-date contents. */
727
728static bool
729copy_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 =

Callers 1

copy_internalFunction · 0.85

Calls 12

set_file_security_ctxFunction · 0.85
set_process_security_ctxFunction · 0.85
cached_umaskFunction · 0.85
fd_has_aclFunction · 0.85
handle_clone_failFunction · 0.85
clone_fileFunction · 0.85
fchmod_or_lchmodFunction · 0.85
copy_file_dataFunction · 0.85
set_ownerFunction · 0.85
copy_attrFunction · 0.85
set_authorFunction · 0.85
emit_debugFunction · 0.85

Tested by

no test coverage detected