From nobody Thu Dec 14 16:07:31 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Srcgl2WbRz52gSD; Thu, 14 Dec 2023 16:07:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Srcgl1dVSz3SCm; Thu, 14 Dec 2023 16:07:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702570051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ux45kw+913AzvG2CP2pjf9PecAPD/08C4IV47O3WwWc=; b=BuC2NAZqOD+uoejtKQqCrFaw4i0AQsXohoUu+ToGYEYoTWD0r+K4GiieuBC5J2oKceEOJE aRjucjOtJDTmaUYsd6/B64tzojMW57sCq8pixgzF/NGX3IUEMqs54Uvyr28cll6jc+oYh+ J2n4KyLzoxulliHZCCguUI8ExjK5zLQrBKA/o2MyBKcU0rRXdiJjDJuiAe/wpx2KjywBkF p/q9XWFENQ6MAC5ig8/kvZcq+x9nAEAyfR7DaD8o04tsPNucUh1uvABuiwldUHou8jdyw2 yqv58S247eL7TI3puhusfUjQoJX8LjPd7+G828ovxry00gHXeDFCLJ8+Cbq2eg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702570051; a=rsa-sha256; cv=none; b=lCo0UnhsaKnqpqpdWesOo8qN2rrvY/FEQ2Q8+SugxV1FPQw1KAGz08CN6kv+ggimM9sEPJ 9XQ2tEIv+y6l/Y4dZEENP0jXz2ljUDZrtYPI2R8Vwo66ejxs5Yw2a0j7ZktXsp3mqrBQ0f rDSyaMGYDjqZ6oIUkAyJ6FQvxYOtMWGutOfGSE6u/2HFTDRKlHPCFKsLV/muNqUMvG6mJ+ dkbIJiCq9bl3w9sSk9PA9TkZDugHcuCicAkP82Ca6PiMwideMqtZMY5GZ380ffApXZoEH2 BJLanQPrDMbWtsSgKNSa+gT6cS13AD9V2/I8xVADBkkc3vWXnbOSDWbgDXOrBg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702570051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ux45kw+913AzvG2CP2pjf9PecAPD/08C4IV47O3WwWc=; b=PhtrnpCoAi7WuT+4bBeWIXB9bVyVIEtfoWNGiYLtrk5QTL1LRG4GYXx9mWXpsFTUwj/kNK cHmhKTjWiBKfoJ9vGCHsPsyh41a/hxWjaPTdcrZHk/264kE0OjfnT+5JknSo/USFO9Bzr9 U48ZFeshzuhn70KQkh83lDoQyLjXEIUc3lX7wROPZujCkLwKqI3MXQwe2p3CmZi1R22rfr yX2XNiVcGHvl0sVBszq/PksJA2viqML221Cyswd/yrqvUiEAABb6EZ1GEKEHqMXiNjIDEJ 5zv/7yOh58r+m7bzB5uimbacshioXf0b56J0qROvf4zViGL3S2ArjzplXwsYig== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Srcgl0kGRzZJs; Thu, 14 Dec 2023 16:07:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BEG7V05015505; Thu, 14 Dec 2023 16:07:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BEG7VlU015502; Thu, 14 Dec 2023 16:07:31 GMT (envelope-from git) Date: Thu, 14 Dec 2023 16:07:31 GMT Message-Id: <202312141607.3BEG7VlU015502@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 38509270663f - main - cp: Further simplify the core logic. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 38509270663f336103273878cc8ddc88a225b9d8 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=38509270663f336103273878cc8ddc88a225b9d8 commit 38509270663f336103273878cc8ddc88a225b9d8 Author: Dag-Erling Smørgrav AuthorDate: 2023-12-14 16:07:04 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-12-14 16:07:04 +0000 cp: Further simplify the core logic. If the destination file exists but we decide unlink it, set the dne flag. This means we don't need to re-check the conditions that would have caused us to delete the file when we later need to decide whether to create or replace it. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D43064 --- bin/cp/utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 891360604631..80a0c1fce824 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -145,6 +145,7 @@ copy_file(const FTSENT *entp, int dne) if (fflag) { /* remove existing destination file */ (void)unlink(to.p_path); + dne = 1; } } @@ -166,7 +167,7 @@ copy_file(const FTSENT *entp, int dne) goto done; } - if (!dne && !fflag) { + if (!dne) { /* overwrite existing destination file */ to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0); } else {