cp: Default to -P when -R is specified

POSIX only specifies the -H, -L, and -P options for use with -R, and
the default is left to the implementation. Without -R, symlinks must
be followed.

Most implementations use -P as the default with -R, which makes sense
to me as default behavior (the source and destination trees are the same).

Since we use the same code for -R and without it, and we allow -H, -L,
and -P without -R, set the default based on the presence of -R. Without
it, use -L as before, as required by POSIX, and with it, use -P to match
the behavior of other implementations.
This commit is contained in:
Michael Forney
2019-12-21 21:08:36 -08:00
parent 61f5d4887a
commit f4b9b966cf
3 changed files with 8 additions and 2 deletions

3
cp.c
View File

@@ -45,6 +45,9 @@ main(int argc, char *argv[])
if (argc < 2)
usage();
if (!cp_follow)
cp_follow = cp_rflag ? 'P' : 'L';
if (argc > 2) {
if (stat(argv[argc - 1], &st) < 0)
eprintf("stat %s:", argv[argc - 1]);