From nobody Wed Feb 23 18:58:40 2022 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 B142E19D18AF; Wed, 23 Feb 2022 18:58:40 +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 4K3lgN4cBHz3lDH; Wed, 23 Feb 2022 18:58:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645642720; 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=7xaP/Yyyo/01UHu2eTdQQnDMXjj7A63Iwc4DhSS3APw=; b=pMVzxpEo6uWbMFhPUU1WxJF8M8P9VpHeDEjnyTp4JURc9nAMeXn2/fXbR7rxT+U6UpHJXO 2aELSVZXjO7lgIhB42UY1PLZ0unI3ZwXhdY708P6P9OYmokRhXvTVIumDrx7rIlXzZ0oTQ JGfD2ewHf1PXwYvk8Tx1/pZ3nPrOtZ5ZNlNWzwBcRAvW03OeYKj5QO19Mk+60k/ZmW16+j 1mAWY8I7e/kDj40/nWvU4RBWm29g7dYP6/0+4irYxoFwI2Sr9omMIMm9uWlPZ7BhifCu7a tFMr81xJ8PHJGf9HlM17k0NjYg1Rf9rtODF0R5dlns9AsH5+bK5CZ4ob1lzuxg== 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 7E64A1D996; Wed, 23 Feb 2022 18:58:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21NIwehV083458; Wed, 23 Feb 2022 18:58:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21NIwedW083457; Wed, 23 Feb 2022 18:58:40 GMT (envelope-from git) Date: Wed, 23 Feb 2022 18:58:40 GMT Message-Id: <202202231858.21NIwedW083457@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 97e13037915c - main - cp: Make -P work without -R as per POSIX 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 97e13037915c22162f199461f56951793d669f57 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645642720; 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=7xaP/Yyyo/01UHu2eTdQQnDMXjj7A63Iwc4DhSS3APw=; b=s3gAQ0YOCkcYcoCJTUXjfgq6MMONJvwZBuVj4D1e1DJNIYKB73vbl6mE/K8AoAE10O51XN FqhrqX/2F9JlKhQtmYHHNLsgwtDjPMGVRAtCaKgnM6BqLKesj8ehEdUfmwjQxIUaWKya9I PZW1ImqD6P3gkmV24/l0/c6Um4kvKJnEmOA5PgRwPYnLUGExkkmDH343pDx+jnsNO3YAu2 O9lvpHd3anVgp90U2JRble0nXD9RlkSD2bqxpiLXqnp7CIGz8inU2XSfpL7R2TIhnkYoJZ c29DXOggshXvMOwpYJ/ni40tuS2oI+AHi9aaeOv3UAAzyS49F6do7eaGHR4FYA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645642720; a=rsa-sha256; cv=none; b=NLI3wXYPEuhIMkUDOUyxeh0gF/aNWQav6tyhpzFQQdVyY8QbUf5W3MNe/U2TuIOMQpVOtv Cx87kRk8gWKeMbcM2+xNFa+ZQP97sYX9vvSPyER20eDNER9kc85M81JYvhu/ajABaCdbyO jX5afnlUo6SyRQDaSgL+HQXBUhWzfAI5M4CNLWLQqUNBe2EBYMSogQnlJmKGi4L8WHJlvA z3srGjjQE3FRw85lOHEOR6+6ECsz43iOSKXfeXzxnu7oQtvO6heRQt9ofHdItIgqOxhRVz UY82WCuokyh70vrgehsqLP6lZ2V3ccEb24qYrnbSeTPYK5fekwREoTbENRRK7A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=97e13037915c22162f199461f56951793d669f57 commit 97e13037915c22162f199461f56951793d669f57 Author: Cameron Katri AuthorDate: 2022-02-23 18:55:13 +0000 Commit: Kyle Evans CommitDate: 2022-02-23 18:55:13 +0000 cp: Make -P work without -R as per POSIX According to POSIX, cp should allow the `-P` flag to work whether `-R` is specified or not. Currently, the `-P` option only works along with `-R`. PR: 199466 Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D30012 --- bin/cp/cp.1 | 16 ++++++++++++---- bin/cp/cp.c | 13 ++++++++----- bin/cp/tests/cp_test.sh | 11 +++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bin/cp/cp.1 b/bin/cp/cp.1 index f7e2d639def7..f6ff23a16f41 100644 --- a/bin/cp/cp.1 +++ b/bin/cp/cp.1 @@ -32,7 +32,7 @@ .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd June 6, 2015 +.Dd February 23, 2022 .Dt CP 1 .Os .Sh NAME @@ -55,6 +55,14 @@ .Op Fl f | i | n .Op Fl alpsvx .Ar source_file ... target_directory +.Nm +.Op Fl f | i | n +.Op Fl alPpsvx +.Ar source_file target_file +.Nm +.Op Fl f | i | n +.Op Fl alPpsvx +.Ar source_file ... target_directory .Sh DESCRIPTION In the first synopsis form, the .Nm @@ -84,10 +92,10 @@ If the .Fl R option is specified, all symbolic links are followed. .It Fl P -If the +No symbolic links are followed. +This is the default if the .Fl R -option is specified, no symbolic links are followed. -This is the default. +option is specified. .It Fl R If .Ar source_file diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 7156c7f10742..f132bb940c09 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -100,21 +100,23 @@ main(int argc, char *argv[]) { struct stat to_stat, tmp_stat; enum op type; - int ch, fts_options, r, have_trailing_slash; + int Pflag, ch, fts_options, r, have_trailing_slash; char *target; fts_options = FTS_NOCHDIR | FTS_PHYSICAL; + Pflag = 0; while ((ch = getopt(argc, argv, "HLPRafilnprsvx")) != -1) switch (ch) { case 'H': Hflag = 1; - Lflag = 0; + Lflag = Pflag = 0; break; case 'L': Lflag = 1; - Hflag = 0; + Hflag = Pflag = 0; break; case 'P': + Pflag = 1; Hflag = Lflag = 0; break; case 'R': @@ -123,6 +125,7 @@ main(int argc, char *argv[]) case 'a': pflag = 1; Rflag = 1; + Pflag = 1; Hflag = Lflag = 0; break; case 'f': @@ -145,7 +148,7 @@ main(int argc, char *argv[]) break; case 'r': rflag = Lflag = 1; - Hflag = 0; + Hflag = Pflag = 0; break; case 's': sflag = 1; @@ -179,7 +182,7 @@ main(int argc, char *argv[]) fts_options &= ~FTS_PHYSICAL; fts_options |= FTS_LOGICAL; } - } else { + } else if (!Pflag) { fts_options &= ~FTS_PHYSICAL; fts_options |= FTS_LOGICAL | FTS_COMFOLLOW; } diff --git a/bin/cp/tests/cp_test.sh b/bin/cp/tests/cp_test.sh index 36d64900f4bb..adb6ea24d9e7 100755 --- a/bin/cp/tests/cp_test.sh +++ b/bin/cp/tests/cp_test.sh @@ -190,6 +190,16 @@ recursive_link_Lflag_body() '(' ! -L foo-mirror/foo/baz ')' } +atf_test_case standalone_Pflag +standalone_Pflag_body() +{ + echo "foo" > bar + ln -s bar foo + + atf_check cp -P foo baz + atf_check -o inline:'Symbolic Link\n' stat -f %SHT baz +} + atf_init_test_cases() { atf_add_test_case basic @@ -202,4 +212,5 @@ atf_init_test_cases() atf_add_test_case recursive_link_dflt atf_add_test_case recursive_link_Hflag atf_add_test_case recursive_link_Lflag + atf_add_test_case standalone_Pflag }