From nobody Mon Apr 08 10:11:41 2024 X-Original-To: dev-commits-src-all@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 4VClHd516hz5GjQW; Mon, 8 Apr 2024 10:11:41 +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 4VClHd3Z5bz4WNn; Mon, 8 Apr 2024 10:11:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712571101; 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=JlKHBr4NFyPm7k1Hjxl2YpF7yUod0MnAaeHwwCxuo2s=; b=VvVr8cbpLLYNYNyiudhsC0/SKSQqksKjW2Xa1s5L2JMDlFytscLsBlH0ZpSYPhAAcidU7Z 8GYYfxM/z19fdhRcHHMlOnWKZ3LuJrxid2wXprnexwlgnTQGcfdAxE+EaQATKJZH/iF8hh 2h+49aNJlZ10DnM8qnGjfc5ctSFd8mnp/L7u9azK47EFjmtnR1UPCq8OIirsKY6iuR6E4q qpGjPrHSC61Y8lyjD+BtB53JFJTuw1lGGpnzKL6FGF69KE7+8qdfmsbMwwEzsL+5+FhUi8 S/bfZK39iE9e92+cZZGSPGwqBKhuOsqI39lITgN9qcmxsedL/aXH/1tmZIIlCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712571101; a=rsa-sha256; cv=none; b=eSo9ul9fXwdCdww4m9J5v+VPpMVtHLg4Dwn+wCpiZKQTzbzc/UTbq8SYnR/Q5foG1kcL7L u7s2HycLYQxZLgvflroY6EqW0i/gotNtVrSrMjQ/s9PrRSdMzDFLttweZnAslyV5X+Dzpr mfKonxHDG5bRBy6farfk8pEUC5IHjlE3EzUNraYUxHnYKpmGsOoN12v2hQkby5D64qbkl5 cKzguMpznNZe1jhLUZ7QU4ExD5afWY/fKRV0AFlUzpKJFzS1FLDaMAvoshW1idlGI3GWIQ 4JTWLDxokKHFPWQiQytQx2tA//FxOAE9WhE0+PM6n/RMVunSp2fBmVMC0PK6rA== 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=1712571101; 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=JlKHBr4NFyPm7k1Hjxl2YpF7yUod0MnAaeHwwCxuo2s=; b=i3yMNJbroBHKy88BO71YSALw8lFcE0zP6t3XJ/pOmT520c99TnpBR+BqBSEoA5qubUeHpc ZNvgGipWHABxhApJVJA8nq1shYyCEDZMPm5yQeBHxECmbJXm2dXOMhCXfzuHBtmddKfpVT 8dqlSJ6YYUvhL/ooBfHr+QBXUVGulR25rZIWiMa/Li/VpY1Q292GArRk6IN6uAbPk/7MkU V0tGMmZpYuJ9059icBFDGd/h1DKZodILCrfWlACVwygznWCG5STDPEGgyITIBgshqhcDqo eEN3U7z+pOUw8f6q6dDe6JiNNAKx1sfW+vGSDNSQTep6TCW2RB5a0WSQcGcipg== 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 4VClHd39hbz15vD; Mon, 8 Apr 2024 10:11:41 +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 438ABfXL093368; Mon, 8 Apr 2024 10:11:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 438ABf6B093365; Mon, 8 Apr 2024 10:11:41 GMT (envelope-from git) Date: Mon, 8 Apr 2024 10:11:41 GMT Message-Id: <202404081011.438ABf6B093365@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 39d543db53a4 - stable/13 - cp: Improved conformance when copying directories. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 39d543db53a456d97e3dec12b22ac191360b8866 Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=39d543db53a456d97e3dec12b22ac191360b8866 commit 39d543db53a456d97e3dec12b22ac191360b8866 Author: Dag-Erling Smørgrav AuthorDate: 2024-04-01 17:28:58 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-04-08 10:10:14 +0000 cp: Improved conformance when copying directories. * When copying a directory, if the destination exists and is not a directory, we would previously emit an error message and exit. The correct behavior according to POSIX is to emit an error message and continue without descending further into the source directory. * When copying a directory, if the destination does not exist and we fail to create it, we would previously emit an error message and exit. The correct behavior according to POSIX is to emit an error message and continue. Whether to descend further into the source directory is explicitly left unspecified; GNU cp does not, which seems to me to be the safer and less surprising option, so let's not either. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D44577 (cherry picked from commit dd286b0dc187c351a9537a363840245d5505b15b) cp: Correct the list of non-portable flags. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D44576 (cherry picked from commit aaa1806f68ef3102a9b888a03360f166b88618c8) --- bin/cp/cp.1 | 8 +++++--- bin/cp/cp.c | 27 ++++++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/bin/cp/cp.1 b/bin/cp/cp.1 index d8d62ef076a1..90b1a158a131 100644 --- a/bin/cp/cp.1 +++ b/bin/cp/cp.1 @@ -31,7 +31,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd December 14, 2023 +.Dd March 28, 2024 .Dt CP 1 .Os .Sh NAME @@ -311,12 +311,14 @@ differ as they copy special files as normal files while recreating a hierarchy. .Pp The +.Fl a , .Fl l , +.Fl N , +.Fl n , .Fl s , .Fl v , -.Fl x and -.Fl n +.Fl x options are non-standard and their use in scripts is not recommended. .Sh SEE ALSO .Xr mv 1 , diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 852868e65dcb..af7d5ffac398 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -519,9 +519,13 @@ copy(char *argv[], enum op type, int fts_options, struct stat *root_stat) * umask blocks owner writes, we fail. */ if (dne) { - if (mkdir(to.p_path, - curr->fts_statp->st_mode | S_IRWXU) < 0) - err(1, "%s", to.p_path); + mode = curr->fts_statp->st_mode | S_IRWXU; + if (mkdir(to.p_path, mode) != 0) { + warn("%s", to.p_path); + (void)fts_set(ftsp, curr, FTS_SKIP); + badcp = rval = 1; + break; + } /* * First DNE with a NULL root_stat is the root * path, so set root_stat. We can't really @@ -530,14 +534,19 @@ copy(char *argv[], enum op type, int fts_options, struct stat *root_stat) * first directory we created and use that. */ if (root_stat == NULL && - stat(to.p_path, &created_root_stat) == -1) { - err(1, "stat"); - } else if (root_stat == NULL) { - root_stat = &created_root_stat; + stat(to.p_path, &created_root_stat) != 0) { + warn("%s", to.p_path); + (void)fts_set(ftsp, curr, FTS_SKIP); + badcp = rval = 1; + break; } + if (root_stat == NULL) + root_stat = &created_root_stat; } else if (!S_ISDIR(to_stat.st_mode)) { - errno = ENOTDIR; - err(1, "%s", to.p_path); + warnc(ENOTDIR, "%s", to.p_path); + (void)fts_set(ftsp, curr, FTS_SKIP); + badcp = rval = 1; + break; } /* * Arrange to correct directory attributes later