From: Paul Eggert Date: Tue, 5 Sep 2023 06:03:52 +0000 (-0700) Subject: cp,mv,install: a bit more up-to-date source stat X-Git-Tag: v9.5~171 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65a1c5b4419985dbedba7284f121f6efb17d6576;p=thirdparty%2Fcoreutils.git cp,mv,install: a bit more up-to-date source stat * src/copy.c (copy_reg): Replace caller’s source status with the more recent version. --- diff --git a/src/copy.c b/src/copy.c index 9f1f3e85a8..66ab006914 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1220,20 +1220,21 @@ handle_clone_fail (int dst_dirfd, char const *dst_relname, *NEW_DST is initially as in copy_internal. If successful, set *NEW_DST to true if the destination file was created and to false otherwise; if unsuccessful, perhaps set *NEW_DST to some value. - SRC_SB is the result of calling follow_fstatat on SRC_NAME. */ + SRC_SB is the result of calling follow_fstatat on SRC_NAME; + it might be updated by calling fstat again on the same file, + to give it slightly more up-to-date contents. */ static bool copy_reg (char const *src_name, char const *dst_name, int dst_dirfd, char const *dst_relname, const struct cp_options *x, mode_t dst_mode, mode_t omitted_permissions, bool *new_dst, - struct stat const *src_sb) + struct stat *src_sb) { char *buf = nullptr; int dest_desc; int dest_errno; int source_desc; - mode_t src_mode = src_sb->st_mode; mode_t extra_permissions; struct stat sb; struct stat src_open_sb; @@ -1273,6 +1274,11 @@ copy_reg (char const *src_name, char const *dst_name, goto close_src_desc; } + /* Might as well tell the caller about the latest version of the + source file status, since we have it already. */ + *src_sb = src_open_sb; + mode_t src_mode = src_sb->st_mode; + /* The semantics of the following open calls are mandated by the specs for both cp and mv. */ if (! *new_dst)