cp: Rename -d option to -P

The -d option is a GNU extension and is equivalent to its "-P
--preserve=links" options.

Since we don't implement the --preserve=links functionality anyway (it
means preserve hard links between files), just call it -P, which is
specified by POSIX.

Additionally, there is no need to check for cp_Pflag again before
copying the symlink itself because the only way the mode in the stat
will indicate a symlink is if we used lstat (which we only do if -P is
specified).
This commit is contained in:
Michael Forney 2014-12-08 03:25:24 +00:00 committed by sin
parent 573ef00c91
commit e14e0becce
4 changed files with 11 additions and 11 deletions

6
cp.1
View File

@ -8,7 +8,7 @@ cp \- copy files and directories
.RI [ name ] .RI [ name ]
.P .P
.B cp .B cp
.RB [ \-adpRrv ] .RB [ \-aPpRrv ]
.RI [ file ...] .RI [ file ...]
.RI [ directory ] .RI [ directory ]
.SH DESCRIPTION .SH DESCRIPTION
@ -21,8 +21,8 @@ they will be copied into the given directory.
preserve mode, timestamp, links and permissions. preserve mode, timestamp, links and permissions.
Implies \-d, \-p, \-r. Implies \-d, \-p, \-r.
.TP .TP
.B \-d .B \-P
don't dereference links. preserve links. don't dereference symbolic links.
.TP .TP
.B \-p .B \-p
preserve mode, timestamp and permissions. preserve mode, timestamp and permissions.

6
cp.c
View File

@ -19,10 +19,10 @@ main(int argc, char *argv[])
ARGBEGIN { ARGBEGIN {
case 'a': case 'a':
/* implies -dpr */ /* implies -dpr */
cp_aflag = cp_dflag = cp_pflag = cp_rflag = 1; cp_aflag = cp_Pflag = cp_pflag = cp_rflag = 1;
break; break;
case 'd': case 'P':
cp_dflag = 1; cp_Pflag = 1;
break; break;
case 'p': case 'p':
cp_pflag = 1; cp_pflag = 1;

2
fs.h
View File

@ -1,7 +1,7 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
extern int cp_aflag; extern int cp_aflag;
extern int cp_dflag;
extern int cp_fflag; extern int cp_fflag;
extern int cp_Pflag;
extern int cp_pflag; extern int cp_pflag;
extern int cp_rflag; extern int cp_rflag;
extern int cp_vflag; extern int cp_vflag;

View File

@ -16,8 +16,8 @@
#include "../util.h" #include "../util.h"
int cp_aflag = 0; int cp_aflag = 0;
int cp_dflag = 0;
int cp_fflag = 0; int cp_fflag = 0;
int cp_Pflag = 0;
int cp_pflag = 0; int cp_pflag = 0;
int cp_rflag = 0; int cp_rflag = 0;
int cp_vflag = 0; int cp_vflag = 0;
@ -39,14 +39,14 @@ cp(const char *s1, const char *s2)
if (cp_vflag) if (cp_vflag)
printf("'%s' -> '%s'\n", s1, s2); printf("'%s' -> '%s'\n", s1, s2);
r = cp_dflag ? lstat(s1, &st) : stat(s1, &st); r = cp_Pflag ? lstat(s1, &st) : stat(s1, &st);
if (r < 0) { if (r < 0) {
weprintf("%s %s:", cp_dflag ? "lstat" : "stat", s1); weprintf("%s %s:", cp_Pflag ? "lstat" : "stat", s1);
cp_status = 1; cp_status = 1;
return 0; return 0;
} }
if (cp_dflag && S_ISLNK(st.st_mode)) { if (S_ISLNK(st.st_mode)) {
if (readlink(s1, buf, sizeof(buf) - 1) >= 0) { if (readlink(s1, buf, sizeof(buf) - 1) >= 0) {
if (cp_fflag) if (cp_fflag)
unlink(s2); unlink(s2);