diff options
-rwxr-xr-x | tests/cp.test | 7 | ||||
-rw-r--r-- | toys/posix/cp.c | 4 |
2 files changed, 9 insertions, 2 deletions
diff --git a/tests/cp.test b/tests/cp.test index c095aad2..040b4f15 100755 --- a/tests/cp.test +++ b/tests/cp.test @@ -127,6 +127,13 @@ testing "--parents b/c/d/file a/" "cp --parents b/c/d/file a/ && cat a/b/c/d/fil rm -rf a/ rm -rf b/ +echo a > file +testing "-P file" "cp -P file fdst && stat -c %F fdst" "regular file\n" "" "" +ln -s file lnk +testing "-P symlink" "cp -P lnk ldst && stat -c %F ldst" "symbolic link\n" "" "" +testing "follow symlink" "cp lnk ldst2 && stat -c %F ldst2" "regular file\n" "" "" +rm file fdst lnk ldst ldst2 + # cp -r ../source destdir # cp -r one/two/three missing # cp -r one/two/three two diff --git a/toys/posix/cp.c b/toys/posix/cp.c index 06f1ff92..fd893ef4 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -38,7 +38,7 @@ config CP -L Follow all symlinks -l Hard link instead of copy -n No clobber (don't overwrite DEST) - -P Do not follow symlinks [default] + -P Do not follow symlinks -p Preserve timestamps, ownership, and mode -R Recurse into subdirectories (DEST must be a directory) -r Synonym for -R @@ -238,7 +238,7 @@ static int cp_node(struct dirtree *try) // Do something _other_ than copy contents of a file? } else if (!S_ISREG(try->st.st_mode) - && (try->parent || (flags & (FLAG_a|FLAG_r)))) + && (try->parent || (flags & (FLAG_a|FLAG_P|FLAG_r)))) { int i; |