From nobody Mon Apr 25 00:03:20 2022 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 27C2F1A80510; Mon, 25 Apr 2022 00:03:22 +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 4KmlbF25KGz3jZx; Mon, 25 Apr 2022 00:03:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650845001; 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=l4EVT33XhNbqlOaHWlnC8jKAXQQm8USeNAuZfHU6qy4=; b=F6KJRy1wZOVze03PtEDpDr4QcNsxHixZpDUy3IIlHUmOQMFbRtHCV6pnhomr3UFJkNCNNs M++945eH2S8gK1fu9SdNQTBwgHy23K6HeW3pO6mP1lrr9LI8U9WDOLLLhhmuAYWqQ2O6kZ rMjXEjdCFDfAuOmNoXcoGOuYBm1ZHQemSUIurVwxWRj7lUdav2FIOkw6Ak7mfbTMOs+lqy JMYPbuNpsvFn1nMOrPPRzsDTnoOFcWdkLkxQf+douyzlGKsGhqpt15cLAtaLUTNuNy8lJk mKQU6asSbWWqKP2c1UOFaxj+b4Ei7Dk97qCQKf3elrPYluhz9JVh8Y9M6va4Ag== 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 24459105D5; Mon, 25 Apr 2022 00:03:21 +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 23P03KmA073575; Mon, 25 Apr 2022 00:03:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23P03K25073574; Mon, 25 Apr 2022 00:03:20 GMT (envelope-from git) Date: Mon, 25 Apr 2022 00:03:20 GMT Message-Id: <202204250003.23P03K25073574@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 19413ce66cc0 - stable/12 - cp: Make -P work without -R as per POSIX 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 19413ce66cc02d676e0778eb9519284e47d7d8e1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650845001; 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=l4EVT33XhNbqlOaHWlnC8jKAXQQm8USeNAuZfHU6qy4=; b=Ow2qDc/pJM+DISNZzJJS1LTYgCXrPozd8wP7ofyeYq1rO9RzayDNEMoi63BB2pHhqnJ9it /12TXEQuoO5rARQSzycwVlEZmmBBZjV3ZsG6AG/ZME7S+eYmo7y6XYnr4yiy3wgDtYmd6v yZx6cc5vaCdOIRaX43yl/pbIeVi2BOGFTaEcwuKWElaROAMEeg9cr1Ggu+0bGg/GM5l6f8 f3oJrHwaOBICE1ieb5dci0/EHPb0EwjVGajZv9lohg+zQnCXvGN90QATsCAFbmOW3X92fy jenvopFfD9ssDkpNyTrVlruC32IYYsv15dKRSlZMjLUzvsntnx5v6TB0ttjCYw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650845001; a=rsa-sha256; cv=none; b=MgRqGClOYiKv8gGyPRspYd+ZCTXUO5Xta1Lf5u/QEtww5n54STB4eiY0vs5AqLhyFaqDS7 VG+SAXXM7I/bYQA/rM1YfCclMrnulbO2pSgMDYsyM/w3kO8m7QjqiVvcb+PbOGv0C0E1r0 0tKuf8nrv/N2sZi7MFscKZQSKUHR6bxpiPhVt1kazCM2lBKou3MumNetVdI2ZlCqL+8L9a 1eBHWxSchIhLR3SixS9mVPYefLY/bdYjVbV/USf5t6MSwxzygBbFDskwfzQ+hTHX/y5i0c eZKxzpGcskISjniRxs5AO1yq/VrzM+5xsxOdfHFs7mg/zXtlARTYG6vA7QGhmw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=19413ce66cc02d676e0778eb9519284e47d7d8e1 commit 19413ce66cc02d676e0778eb9519284e47d7d8e1 Author: Cameron Katri AuthorDate: 2022-02-23 18:55:13 +0000 Commit: Kyle Evans CommitDate: 2022-04-25 00:02:30 +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 (cherry picked from commit 97e13037915c22162f199461f56951793d669f57) --- 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 2c4e2bd7bd3c..e38cd97f4369 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 a9eb65f463d8..7362168d7303 100755 --- a/bin/cp/tests/cp_test.sh +++ b/bin/cp/tests/cp_test.sh @@ -199,6 +199,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 @@ -211,4 +221,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 }