]> git.cameronkatri.com Git - freebsd-patches.git/blob - cp-1-Make-P-work-without-R-as-per-POSIX.patch
Remove upstreamed patch
[freebsd-patches.git] / cp-1-Make-P-work-without-R-as-per-POSIX.patch
1 From a8829b10000d33dd08471af6f3f1e2b55f4df6f6 Mon Sep 17 00:00:00 2001
2 From: Cameron Katri <me@cameronkatri.com>
3 Date: Sun, 19 Sep 2021 20:11:20 -0400
4 Subject: [PATCH] cp(1): Make -P work without -R as per POSIX
5
6 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.
7
8 PR: 199466
9 ---
10 bin/cp/cp.1 | 8 ++++----
11 bin/cp/cp.c | 16 ++++++++++------
12 2 files changed, 14 insertions(+), 10 deletions(-)
13
14 diff --git a/bin/cp/cp.1 b/bin/cp/cp.1
15 index f7e2d639def..c9e62553bc5 100644
16 --- a/bin/cp/cp.1
17 +++ b/bin/cp/cp.1
18 @@ -32,7 +32,7 @@
19 .\" @(#)cp.1 8.3 (Berkeley) 4/18/94
20 .\" $FreeBSD$
21 .\"
22 -.Dd June 6, 2015
23 +.Dd August 24, 2021
24 .Dt CP 1
25 .Os
26 .Sh NAME
27 @@ -84,10 +84,10 @@ If the
28 .Fl R
29 option is specified, all symbolic links are followed.
30 .It Fl P
31 -If the
32 +No symbolic links are followed.
33 +This is the default if the
34 .Fl R
35 -option is specified, no symbolic links are followed.
36 -This is the default.
37 +option is specified.
38 .It Fl R
39 If
40 .Ar source_file
41 diff --git a/bin/cp/cp.c b/bin/cp/cp.c
42 index 3a23394df35..d1612003542 100644
43 --- a/bin/cp/cp.c
44 +++ b/bin/cp/cp.c
45 @@ -99,7 +99,7 @@ main(int argc, char *argv[])
46 {
47 struct stat to_stat, tmp_stat;
48 enum op type;
49 - int Hflag, Lflag, ch, fts_options, r, have_trailing_slash;
50 + int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash;
51 char *target;
52
53 fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
54 @@ -108,13 +108,14 @@ main(int argc, char *argv[])
55 switch (ch) {
56 case 'H':
57 Hflag = 1;
58 - Lflag = 0;
59 + Lflag = Pflag = 0;
60 break;
61 case 'L':
62 Lflag = 1;
63 - Hflag = 0;
64 + Hflag = Pflag = 0;
65 break;
66 case 'P':
67 + Pflag = 1;
68 Hflag = Lflag = 0;
69 break;
70 case 'R':
71 @@ -123,6 +124,7 @@ main(int argc, char *argv[])
72 case 'a':
73 pflag = 1;
74 Rflag = 1;
75 + Pflag = 1;
76 Hflag = Lflag = 0;
77 break;
78 case 'f':
79 @@ -145,7 +147,7 @@ main(int argc, char *argv[])
80 break;
81 case 'r':
82 rflag = Lflag = 1;
83 - Hflag = 0;
84 + Hflag = Pflag = 0;
85 break;
86 case 's':
87 sflag = 1;
88 @@ -180,8 +182,10 @@ main(int argc, char *argv[])
89 fts_options |= FTS_LOGICAL;
90 }
91 } else {
92 - fts_options &= ~FTS_PHYSICAL;
93 - fts_options |= FTS_LOGICAL | FTS_COMFOLLOW;
94 + if (!Pflag) {
95 + fts_options &= ~FTS_PHYSICAL;
96 + fts_options |= FTS_LOGICAL | FTS_COMFOLLOW;
97 + }
98 }
99 (void)signal(SIGINFO, siginfo);
100
101 --
102 2.32.0
103