Date: Thu, 14 Dec 2023 16:07:31 GMT From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 38509270663f - main - cp: Further simplify the core logic. Message-ID: <202312141607.3BEG7VlU015502@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=38509270663f336103273878cc8ddc88a225b9d8 commit 38509270663f336103273878cc8ddc88a225b9d8 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2023-12-14 16:07:04 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> 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 {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202312141607.3BEG7VlU015502>