From nobody Mon Apr 01 17:44:38 2024 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 4V7dgW0vkDz5GVd7; Mon, 1 Apr 2024 17:44:39 +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 4V7dgW09lQz4htn; Mon, 1 Apr 2024 17:44:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711993479; 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=ttWtcHkv0HcTjBapCTc4lZXXIHeXqrfCfVtAJlOqscI=; b=Fi/m5D6Qo5rNtso4+x8kTOVAxeO6rZdDIoQ9q/Imv8zh3k4//pgphike1tX64FF5kXw4UW UEd4g6LLHWH8kU2WmNuVryNoswKdaMOJrY3p1EnDhLOXfKhaxbSvP/RxmTbrnS/51vUNI5 iQsSYyZ+pJDtRASlrWU9EPK60giwjHXrDWArZTeFmJm0ZZ4+xxoWSHmGE5O4thpLdtDtEH 8PURkr8501CbYJ5gxQFygN3fLP+ELHYl+XvQwECXL1R8Y+kkR60L0brzfO0hc2conP18vt yQwofGYsdu1AR3nBgRFvTTNIF8Rw5/QdSePWyZ4NT9xhb+5J/ns3ipLAELhhCw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711993479; a=rsa-sha256; cv=none; b=YSdmYW84ZWK4KN5cx6Xk8ZhEvxLOCYi32QvQUyJfzMwmbkUwge5eLmnLj21FquFuc5t/U3 5QEOLW5cvUZ7nNcg7Z05cpy3ZVyvFC5Y4Pk+aXHIiVsyhETMrcTqY2xYeKohi6Nrm4WJLB 3ScsTu08NhC1FP8Z3IDETefsr2ANIP+cswJqSytXtU0RX492caIu8kILVj19ZYisZaJPno d88lUhrCBBCxSUKSWQGqwg1JfTibGrdz1dwlqHy3LKIQEdd3w1vw391GmzetEYQ5HSflKQ 50HHxyCvKCXr3ThJRNlx8yscNYC7bq6V3+K49jngNvERlHK/JGY72AvSdszeRw== 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=1711993479; 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=ttWtcHkv0HcTjBapCTc4lZXXIHeXqrfCfVtAJlOqscI=; b=R8hdUhr0uD21kV8tlP3TExbQz+IkxOZRXZcVO8jd9Vux8ritdYanWiqsqfo8t710DdjCuR t0D5cF4IeCEsoC/VV841DMn3yeI2A8IOnhSGDpnY6YRk7wwotiQyOEaG9OyzYBM5G0Nmwf 6yIdKA1VSdIB1mFU01Q8se5Lk+0/vv9dZBC7+jymMr9nLstjSyLUiGZQxg+OsMnt5ze/fJ e+NP+GjLm9f5bVs4X6HrHB45IFH/bE/13yIFMzBhPDE0NyEzy6dkUP47ae43bIxSNwLvVc PJ95ljuK2y/xjgZLfY6v/QkIsTMPcsvk70J0iAox8zxoFnLwJ66KCVRoFpr5Qg== 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 4V7dgV6WQVzFwh; Mon, 1 Apr 2024 17:44:38 +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 431HicgQ074350; Mon, 1 Apr 2024 17:44:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 431HicxH074347; Mon, 1 Apr 2024 17:44:38 GMT (envelope-from git) Date: Mon, 1 Apr 2024 17:44:38 GMT Message-Id: <202404011744.431HicxH074347@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: dd286b0dc187 - main - cp: Improved conformance when copying directories. 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: dd286b0dc187c351a9537a363840245d5505b15b Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=dd286b0dc187c351a9537a363840245d5505b15b commit dd286b0dc187c351a9537a363840245d5505b15b Author: Dag-Erling Smørgrav AuthorDate: 2024-04-01 17:28:58 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-04-01 17:29:31 +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 --- bin/cp/cp.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 14d1cc2a3f75..02b879006a4f 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -506,9 +506,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 @@ -517,14 +521,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