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.
This commit is contained in:
Paul Eggert committed 2023-09-04 23:12:02 -07:00
1 parent 9cd52bd999
commit 65a1c5b441
1 file changed
+9 -3
+9 -3
View File
@@ -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)