git: 4336161cc9c6 - main - install: Don't skip syncing in the common case.

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Fri, 12 Apr 2024 17:31:48 UTC
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=4336161cc9c631d40d00adee97dfc8161b6bec9f

commit 4336161cc9c631d40d00adee97dfc8161b6bec9f
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2024-04-12 17:30:55 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2024-04-12 17:31:35 +0000

    install: Don't skip syncing in the common case.
    
    In `copy()`, if no digest was requested (which is the common case), we
    use `copy_file_range()` to avoid needlessly copying the contents of the
    file into user space and back.  When `copy_file_range()` returns
    successfully (which, again, is the common case), we simply return, and
    therefore never get to the point where we call `fsync()` if the `-S`
    option was specified.  Fix this.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D44756
---
 usr.bin/xinstall/xinstall.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index 6ab0a88d5cd7..d696a8429c88 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -1232,15 +1232,12 @@ copy(int from_fd, const char *from_name, int to_fd, const char *to_name,
 #ifndef BOOTSTRAP_XINSTALL
 	/* Try copy_file_range() if no digest is requested */
 	if (digesttype == DIGEST_NONE) {
-		ret = 1;
-		while (ret > 0) {
+		do {
 			ret = copy_file_range(from_fd, NULL, to_fd, NULL,
 			    SSIZE_MAX, 0);
-		}
-		if (ret == 0) {
-			/* DIGEST_NONE always returns NULL */
-			return (NULL);
-		}
+		} while (ret > 0);
+		if (ret == 0)
+			goto done;
 		if (errno != EINVAL) {
 			serrno = errno;
 			(void)unlink(to_name);
@@ -1313,6 +1310,7 @@ copy(int from_fd, const char *from_name, int to_fd, const char *to_name,
 			err(EX_OSERR, "%s", from_name);
 		}
 	}
+done:
 	if (safecopy && fsync(to_fd) == -1) {
 		serrno = errno;
 		(void)unlink(to_name);