HomeFreeBSD

cp: Add tests for hard link case.

Description

cp: Add tests for hard link case.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43052

(cherry picked from commit 1fead66b64822f3f8106ad09bef0b9656836fa1a)

cp: Add tests for symbolic link case.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans, allanjude
Differential Revision: https://reviews.freebsd.org/D43054

(cherry picked from commit d3a8e9b43b4cef5b80e3845dfa8fd1fec6e568f9)

cp: Refactor the core logic.

Rewrite copy_file() so the lflag and sflag are handled as early as
possible instead of constantly checking that they're not set and then
handling them at the end. This also opens the door to changing the
failure logic at some future point (for instance, we might decide to
fall back to copying if errno indicates that the file system does not
support links).

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans, allanjude
Differential Revision: https://reviews.freebsd.org/D43055

(cherry picked from commit d002316fd7bf0b359ea2f5518f3c10f6ad89a9ac)

cp: Split the basic_symlink test case in two.

This test case tests two different things: first, that copying a symlink
results in a file with the same contents as the target of the symlink,
rather than a second symlink, and second, that cp will refuse to copy a
file to itself, or to a link to itself, or a link to its target. Leave
the first part in basic_symlink, move the second part to a new test case
named samefile, and slightly expand both cases.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43062

(cherry picked from commit ac56b9d83c75f548667912ffe422be6bd4f5c27e)

cp: Move the flags around a bit.

  • The HLPR flags are grouped together at the beginning because they are the standard flags for programs using FTS. Move the N flag out from among them to its correct place in the sequence.
  • The Pflag variable isn't used outside main(), but moving it out lets us skip initialization and keeps it with its friends H, L and R.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43063

(cherry picked from commit 0f4467ce444b201468d2268958130f495951ca3c)

cp: Further simplify the core logic.

If the destination file exists but we decide unlink it, set the dne
flag. This means we don't need to re-check the conditions that would
have caused us to delete the file when we later need to decide whether
to create or replace it.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43064

(cherry picked from commit 38509270663f336103273878cc8ddc88a225b9d8)

cp: Move the -N flag in the manual page.

This accidentally got left out of 0f4467ce444b.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans, allanjude
Differential Revision: https://reviews.freebsd.org/D43067

(cherry picked from commit 53fc8e190241233d94e183f8a39ec39f2154dfa8)

Details

Provenance
desAuthored on Dec 13 2023, 9:31 PM
Reviewer
kevans
Differential Revision
D43052: cp: Add tests for hard link case.
Parents
rG0fcf3a6235ee: cp: Add -N flag, inspired by NetBSD's similar flag
Branches
Unknown
Tags
Unknown