aboutsummaryrefslogtreecommitdiff
path: root/bin/cp/tests
Commit message (Collapse)AuthorAgeFilesLines
* cp: Fix copying the root directoryDag-Erling Smørgrav2025-11-221-0/+15
| | | | | | | | | | | | When the source of the copy operation is the root directory, we should neither append it to the destination path on FTS_D nor trim it back off on FTS_DP. PR: 291132 MFC after: 3 days Fixes: 82fc0d09e862 ("cp: Partly restore symlink folllowing.") Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D53863
* cp: Simplify sameness checksDag-Erling Smørgrav2025-10-071-4/+4
| | | | | | Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D52926
* cp: Drop test helperDag-Erling Smørgrav2025-09-163-76/+1
| | | | | | | | | Now that stat(1) can report whether a file is sparse, we no longer need a helper program for our tests. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D52482
* cp: Add descriptions to all test cases.Dag-Erling Smørgrav2025-07-091-11/+164
| | | | | | | | While here, touch a few test cases up. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51124
* cp: Add an option to visit sources in order.Dag-Erling Smørgrav2025-07-091-2/+2
| | | | | | | | | | This adds a --sort option which makes cp pass a comparison function to FTS, ensuring that sources are visited and traversed in a predictable order. This will help make certain test cases more reliable. Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D51214
* cp: Add GNU-compatible long options.Dag-Erling Smørgrav2025-07-091-0/+16
| | | | | | | | | While here, fully switch boolean variables from int to bool, and clean up the manual page a little. Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D51213
* cp: Fix typo in test case.Dag-Erling Smørgrav2025-07-021-1/+1
| | | | | Fixes: eb439266b433 Sponsored by: Klara, Inc.
* cp: Don't rely on FTS_DP to keep track of depth.Dag-Erling Smørgrav2025-07-021-0/+73
| | | | | | | | | | | | | | | | | | | | | In normal operation, we get an FTS_D entry when we enter a directory and a matching FTS_DP entry when we leave it. However, if an error occurs either changing to or reading a directory, we may get an FTS_D entry followed by FTS_DNR or even FTS_ERR instead. Since FTS_ERR can also occur for non-directory entries, the only reliable way to keep track of when we leave a directory is to compare fts_level to our own depth counter. This fixes a rare assertion when attempting to recursively copy a directory tree containing a directory which is either not readable or not searchable. While here, also add a test case for directory loops. Fixes: 82fc0d09e8625 Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D51096
* cp: Fix improper use of O_PATH.Dag-Erling Smørgrav2025-06-231-0/+18
| | | | | | | | | | | | This does not appear to make any practical difference at the moment, but technically `O_PATH` means “I'm not going to use this descriptor for any other purposes than vnode lookups”, so using it to read the directory's ACLs is improper and might fail in the future. Fixes: 82fc0d09e8625 Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D50984
* cp: Improve -p flag tests.Dag-Erling Smørgrav2025-06-101-24/+32
| | | | | | | | | In addition to verifying that ACLs and flags are copied with the -p flag, verify that they are not copied without it. Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D50714
* cp: Improve to_root test case.Dag-Erling Smørgrav2025-05-311-8/+9
| | | | | | | | | | Since the bug we're testing involved path name construction, we don't need to be root to test it; we can simply check the error message. Fixes: 537fbf70f12b Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D50628
* cp: Fix copying to root directory.Dag-Erling Smørgrav2025-05-301-0/+22
| | | | | | | | | | | The trailing-slash logic would strip the target down to an empty string, which we would then fail to stat, and subsequently attempt (and fail) to create. Fixes: 82fc0d09e862 Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D50604
* atf: Don't be deterred by weird umasks.Dag-Erling Smørgrav2025-05-241-10/+1
| | | | | | | | | | | | If the current umask is weird, ATF goes to great lengths to tell us that it can't possibly work in these conditions, instead of just dealing with it. This makes it unreasonably hard to use ATF to test how our own code handles unusual umasks. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: igoro, kevans, ngie Differential Revision: https://reviews.freebsd.org/D50267
* cp: Fix issues with destination directory mode.Dag-Erling Smørgrav2025-05-101-0/+23
| | | | | | | | | | | | Ensure that we are able to enter the destination directory after we create it, even if the current umask would normally prevent it, and that it has the expected permissions once we are done, even if we had to tweak them to be able to enter it. Fixes: 82fc0d09e862 Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D50266
* cp: Fix dead link case.Dag-Erling Smørgrav2025-05-101-3/+8
| | | | | | | | | | | | The test case was a) not doing what I intended it to do and b) missing a third possible configuration. Fix the test case, and fix the code by not setting the beneath flag (which restricts operations to the destination tree) unless we are recursing. Fixes: 82fc0d09e862 Sponsored by: Klara, Inc. Reviewed by: allanjude, markj Differential Revision: https://reviews.freebsd.org/D50257
* cp: Partly restore symlink folllowing.Dag-Erling Smørgrav2025-05-061-0/+169
| | | | | | | | | | | | | | | | | | | | * As a general rule, follow symbolic links in the destination as long as the target is within the destination hierarchy. * As a special case, allow the destination itself to be a symbolic link, and even a dead one (in which case we create the target). * The file-to-file case remains unrestricted. Currently, if a symlink we aren't allowed to follow is encountered, cp will behave just like it would if the file was not writable. We should consider whether it would be better to replace the offending link instead. Fixes: 0729d1e8fd90 MFC after: never Relnotes: yes Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D50093
* Remove residual blank line at start of MakefileWarner Losh2024-07-151-1/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* cp: Never follow symbolic links in destination.Dag-Erling Smørgrav2024-04-081-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Historically, BSD cp has followed symbolic links in the destination when copying recursively, while GNU cp has not. POSIX is somewhat vague on the topic, but both interpretations are within bounds. In 33ad990ce974, cp was changed to apply the same logic for symbolic links in the destination as for symbolic links in the source: follow if not recursing (which is moot, as this situation can only arise while recursing) or if the `-L` option was given. There is no support for this in POSIX. We can either switch back, or go all the way. Having carefully weighed the kind of trouble you can run into by following unexpected symlinks up against the kind of trouble you can run into by not following symlinks you expected to follow, we choose to go all the way. Note that this means we need to stat the destination twice: once, following links, to check if it is or references the same file as the source, and a second time, not following links, to set the dne flag and determine the destination's type. While here, remove a needless complication in the dne logic. We don't need to explicitly reject overwriting a directory with a non-directory, because it will fail anyway. Finally, add test cases for copying a directory to a symlink and overwriting a directory with a non-directory. MFC after: never Relnotes: yes Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D44578
* cp: Split the basic_symlink test case in two.Dag-Erling Smørgrav2023-12-141-5/+19
| | | | | | | | | | | | | | 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
* cp: Add tests for symbolic link case.Dag-Erling Smørgrav2023-12-131-0/+31
| | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans, allanjude Differential Revision: https://reviews.freebsd.org/D43054
* cp: Add tests for hard link case.Dag-Erling Smørgrav2023-12-131-0/+32
| | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D43052
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-162-2/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* cp: Adjust the sparse file tests.Dag-Erling Smørgrav2023-02-083-23/+98
| | | | | | | | | | | * The sparsity check was ineffective: it compared the apparent size in bytes to the actual size in blocks. Instead, write a tool that reliably detects sparseness. * Some of the seq commands were missing an argument. * Based on empirical evidence, 1 MB holes are not necessarily large enough to be preserved by the underlying filesystem. Increase the hole size to 16 MB. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: cracauer Differential Revision: https://reviews.freebsd.org/D38414
* cp: Add tests involving sparse files.Dag-Erling Smørgrav2023-02-021-0/+90
| | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38290
* cp: fix -R recursion detectionKyle Evans2022-04-061-3/+12
| | | | | | | | | | | | | | | | | | | | | | The correct logic is a lot simpler than the previous iteration. We record the base fts_name to avoid having to worry about whether we needed the root symlink name or not (as applicable), then we can simply shift all of that logic to after path translation to make it less fragile. If we're copying to DNE, then we'll have swapped out the NULL root_stat pointer and then attempted to recurse on it. The previously nonexistent directory shouldn't exist at all in the new structure, so just back out from that tree entirely and move on. The tests have been amended to indicate our expectations better with subdirectory recursion. If we copy A to A/B, then we expect to copy everything from A/B/* into A/B/A/B, with exception to the A that we create in A/B. Reviewed by: bapt Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D34655
* cp: Make -P work without -R as per POSIXCameron Katri2022-02-231-0/+11
| | | | | | | | | | 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`. PR: 199466 Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D30012
* cp: fix -R with linksKyle Evans2022-02-221-0/+64
| | | | | | | | | | The traversal was previously not properly honoring -H/-L/-P. Notably, we should not have been resolving symlinks encountered during traversal when either -H or -P are specified. Sponsored by: Klara, Inc. Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D34063
* cp: fix some cases with infinite recursionKyle Evans2022-01-271-0/+77
| | | | | | | | | | | | | | | | | | | | | | As noted in the PR, cp -R has some surprising behavior. Typically, when you `cp -R foo bar` where both foo and bar exist, foo is cleanly copied to foo/bar. When you `cp -R foo foo` (where foo clearly exists), cp(1) goes a little off the rails as it creates foo/foo, then discovers that and creates foo/foo/foo, so on and so forth, until it eventually fails. POSIX doesn't seem to disallow this behavior, but it isn't very useful. GNU cp(1) will detect the recursion and squash it, but emit a message in the process that it has done so. This change seemingly follows the GNU behavior, but it currently doesn't warn about the situation -- the author feels that the final product is about what one might expect from doing this and thus, doesn't need a warning. The author doesn't feel strongly about this. PR: 235438 Reviewed by: bapt Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D33944
* cp: tests: fix weird 20 insertionKyle Evans2020-09-231-1/+2
| | | | | | | This slipped in at the last moment. =( Notes: svn path=/head/; revision=366060
* cp: add some basic testsKyle Evans2020-09-232-0/+70
There are some tests available in the NetBSD test suite, but we don't currently pass all of those; further investigation will go into that. For now, just add a basic test as well as a test that copies from /dev/null to a file. The /dev/null test confirms that the file gets created if it's empty, then that it truncates the file if it's non-empty. This matches some usage that was previously employed in the build and was replaced in r366042 by a simpler shell construct. I will also plan on coming back to expand these in due time. MFC after: 1 week Notes: svn path=/head/; revision=366059