From 65a1c5b4419985dbedba7284f121f6efb17d6576 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 4 Sep 2023 23:03:52 -0700 Subject: [PATCH] cp,mv,install: a bit more up-to-date source stat MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/copy.c (copy_reg): Replace caller’s source status with the more recent version. --- src/copy.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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) -- 2.47.2