From nobody Mon Apr 08 10:11:03 2024 X-Original-To: dev-commits-src-branches@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 4VClGv43xmz5GhrD; Mon, 8 Apr 2024 10:11:03 +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 4VClGv23Mnz4VBG; Mon, 8 Apr 2024 10:11:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712571063; 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=lsZdY5ERIUw78PsunJzO6t58G3/gwBhMp7kTthswCe4=; b=U4adsMTCnv+m2Ok7qf8jh+EpoB+vAvM11c6atMhksLQlljhmzmaZOCD8ElgY7azAWJQ2B8 PX2w+uI1QaKOn8wuqLxzxUO024GMaYXYNpaEjIJ547hRNbQB6RgcF2zLoesrjJqLM3QVOV SCgAI7KxpkYm/OMPm5rtkq7dulaeyjab7u6YzUTmT61nPKze1PLkLqAWkXsVaRSXhmJ9vV c11F0wtgkQKwtJRkcr2ZfhVVKvMZsl2sXEZ06/OWTUKtZsNJ4+AHy/+i77iteEywerNFha ZgQtgJZMrSP/7cW61NNIyZzg0tqjh2pMpGiAQwvtIE28eSye0o4tNq1dl1mHZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712571063; a=rsa-sha256; cv=none; b=PSLfm3qSljqt058Dhksl13CCczU7O3vDYtMM409mXeLo8MZE330MGfGYZSy56bLyr6PGK+ i8cxT5c/xNWNVd43Tn08Yp30w1gzNA0df4R1kxifxFg4jTHz96x0utjviExS085AGW0BlH LwsoUt7MbXWtSLRvXXEq3gUMYkViF5nhBQu/GcpUmPMftQKm2o72vn53mPj82asaNpllzs jifdiKqxYxtBklftvaz2aoqW63+h9Oq+WfPRlErkGEyy8vf8ROpPwb/OkYs83WQKUHjKSW o3EsSVUAd8gszk0oSB+bSEcYFrvr+kfUZrmyLpE7dBuirkvm6cz+vaIPKJ+FNg== 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=1712571063; 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=lsZdY5ERIUw78PsunJzO6t58G3/gwBhMp7kTthswCe4=; b=RtMwIMyOU7IYf26I9X1uMoj63X9IbO+AEU5wQL0tF/V8YYMq/0DYvA/j/sssMkbBYPZ1Ke xPJfn+n2XHqnHoLL3MUIxMSA6Fn12SubwDzrzW95iSeHw+UHVwJbRTlYfH4cjq0UrclDgF u9rKzqKi4ebjhF20td3z+YRx0q4vs7MSZfvvECWifK0ibgSHdqTTNBPTEQJ7+IloS7YLNE In7TV4ScKkVRFzIxRtAeXOetrXLiCDqszjr3/afK9ro/qVbodyxZz7pk0r1dgYCm+ENOLo ttP1S3R408mVgRRYfX5x+DAPRIpCLH9GTyt+eKsPm4QJpe5JfgbferppNVwOjg== 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 4VClGv1g3Jz15v0; Mon, 8 Apr 2024 10:11:03 +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 438AB30W091795; Mon, 8 Apr 2024 10:11:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 438AB34R091792; Mon, 8 Apr 2024 10:11:03 GMT (envelope-from git) Date: Mon, 8 Apr 2024 10:11:03 GMT Message-Id: <202404081011.438AB34R091792@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: 2ad8333c6534 - stable/14 - cp: Improved conformance when copying directories. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/14 X-Git-Reftype: branch X-Git-Commit: 2ad8333c653432a187ccea8c6b2de4a35eb6d0ff Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=2ad8333c653432a187ccea8c6b2de4a35eb6d0ff commit 2ad8333c653432a187ccea8c6b2de4a35eb6d0ff Author: Dag-Erling Smørgrav AuthorDate: 2024-04-01 17:28:58 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-04-08 10:10:41 +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