summaryrefslogtreecommitdiffstats
path: root/tests/cp
AgeCommit message (Collapse)AuthorLines
2026-03-02test: cp: add test for non-UTF8 directory namesSylvestre Ledru-0/+47
Missing test identified here: https://github.com/uutils/coreutils/pull/11148 * tests/cp/non-utf8-name.sh: Add a new test to cover this case. https://github.com/coreutils/coreutils/pull/207
2026-02-18tests: use system ENOTSUP messagePádraig Brady-5/+6
* tests/cp/cp-mv-enotsup-xattr.sh: Don't hardcode "Operation not supported". * tests/cp/cp-a-selinux.sh: Likewise.
2026-02-18maint: tests: avoid AIX specific EACCES handlingPádraig Brady-11/+5
* tests/rm/inaccessible.sh: Remove AIX specific handling. * tests/cp/fail-perm.sh: Likeise. Also remove confusing EPERM/HPUX mentions. * tests/misc/sync.sh: Don't hardcode EISDIR and EACCES.
2026-02-12tests: cp: ensure --debug output failure is diagnosedoech3-0/+5
* tests/cp/debug.sh: cp diagnostics are written to stdout, so ensure output errors are diagnosed. https://github.com/coreutils/coreutils/pull/192
2026-02-07tests: cp: ensure read-only dir perms preservedSylvestre Ledru-0/+65
* tests/cp/readonly-dir.sh: Add new test. * tests/local.mk: Reference new test. Identified here https://github.com/uutils/coreutils/issues/7961
2026-01-06tests: cp: fix always skipped nfs-removal-race.shPádraig Brady-1/+13
* tests/cp/nfs-removal-race.sh: This test was invalid since v8.32 as we now use fstatat() rather than stat(). Also since commit v9.0-66-ge2daa8f79 we leverage the errno from open(O_DIRECTORY) to avoid a stat, so pass --no-target-directory to ensure fstatat() is called. Discussed in https://github.com/coreutils/coreutils/pull/161
2026-01-06tests: cp: support glibc 2.33+ in nfs-removal-race testChristopher Illarionova-7/+43
glibc 2.33 removed __xstat, making stat() a direct symbol. This test previously only intercepted __xstat, causing it to skip on modern glibc with 'LD_PRELOAD was ineffective'. Changes: - Intercept both __xstat (glibc < 2.33) and stat (glibc >= 2.33) - Only mark 'preloaded' when stat is called on destination 'd', ensuring the test verifies cp actually stats the destination
2026-01-01maint: run 'make update-copyright'Collin Funk-64/+64
2025-11-30tests: copy: reinstate check for symlink xattr copyingPádraig Brady-1/+27
* tests/cp/cp-mv-enotsup-xattr.sh: Use two xattr supporting file systems, to verify the propagation of xattrs.
2025-11-30tests: avoid skip due to missing nouser_xattr supportPádraig Brady-35/+18
* tests/cp/cp-mv-enotsup-xattr.sh: The nouser_xattr option is not supported by ext2 since about 2022. Instead use ramfs to ensure xattrs are not supported. We also remove part of the test that relied on partial xattr support. Fixes https://github.com/coreutils/coreutils/issues/135
2025-11-01copy: don't avoid copy-offload upon SEEK_HOLE indicating non-sparsePádraig Brady-0/+10
* src/copy-file-data.c (infer_scantype): Fall back to a plain copy if SEEK_HOLE indicates non-sparse, as zero copy avoids copy offload. This was seen with transparently compressed files on OpenZFS. * tests/cp/sparse-perf.sh: Add a test case even though it might only trigger on compressed file systems that don't support reflink. * NEWS: Mention the bug fix. Addresses https://github.com/coreutils/coreutils/issues/122
2025-08-23tests: cp: ensure copy offload is not disabled for sparse filesPádraig Brady-1/+20
Related to commits v9.1-109-g879d2180d and v9.7-248-g306de6c26 * tests/cp/sparse-perf.sh: This edge case was missed a couple of times, so add a test to ensure we attempt copy offload.
2025-05-21tests: avoid hung tests on older macOSPádraig Brady-2/+2
These tests were seen to hang on PPC Mac OS X 10.4.11 * tests/cp/existing-perm-race.sh: Protect fifo interactions with a 1 minute timeout. * tests/cp/file-perm-race.sh: Likewise. Reported in https://bugs.gnu.org/78509
2025-01-20tests: remove use of unprotected 'set'Pádraig Brady-1/+1
* cfg.mk (sc_prohibit_bare_set): A new syntax check to ensure we protect use of set with '--', so that args beginning with '-' are not interpreted as options, and if no args are present, all existing args are cleared. * tests/cp/symlink-slash.sh: Add -- to unprotected use of set. * tests/ls/ls-time.sh: Likewise. * tests/ls/symlink-slash.sh: Likewise. * tests/mkdir/perm.sh: Likewise. * tests/mkdir/selinux.sh: Likewise. * tests/mkdir/smack-no-root.sh: Likewise. * tests/mkdir/smack-root.sh: Likewise. * tests/mv/part-hardlink.sh: Likewise. * tests/nice/nice.sh: Likewise. * tests/stty/stty-row-col.sh: Likewise.
2025-01-07cp,mv: decouple --update from -f,-i,-n optionsPádraig Brady-0/+3
* src/copy.h: Change update member from bool to enum. * src/copy.c: s/interactive == I_ALWAYS_NO/update == UPDATE_NONE_FAIL/; s/interactive == I_ALWAYS_SKIP/update == UPDATE_NONE/; s/update/update == UPDATE_OLDER/; * src/install.c: Init with UPDATE_ALL, rather than false. * src/cp.c: Likewise. Simply parse -f,-i,-n to x.interactive, and parse --update to x.update. * src/mv.c: Likewise. * tests/cp/cp-i.sh: Add a test case where -n --update -i honors the --update option, which would previously have been ignored due to the preceding -n.
2025-01-06cp,mv: ensure -i,f are not overridden by -uPádraig Brady-0/+19
Since coreutils 9.3 we had --update={all,older} override -i. In coreutils 9.5 this was expanded to -u (to make it consistent with --update=older). This patch reinstates things so that -i combines with -u instead. I.e. have -i be protective, rather than selective (like -u). The -f option of mv is similarly adjusted in this patch, so now --update does not override any of -f,-i,-n. * NEWS: Mention the bug fix. * src/cp.c (main): Don't have -u disable prompting. * src/mv.c (main): Likewise. * tests/cp/cp-i.sh: Add a test case for -i. * tests/mv/update.sh: Likewise. * tests/mv/i-3.sh. Add a test case for -f. Fixes https://bugs.gnu.org/70887
2025-01-01maint: update all copyright year number rangesPádraig Brady-64/+64
Update to latest gnulib with new copyright year. Run "make update-copyright" and then... * gnulib: Update included in this commit as copyright years are the only change from the previous gnulib commit. * tests/init.sh: Sync with gnulib to pick up copyright year. * bootstrap: Likewise. * tests/sample-test: Adjust to use the single most recent year.
2024-02-26cp,mv: add --update=none-fail to fail if existing filesPádraig Brady-0/+3
* src/cp.c (main): Add support for --update=none-fail to provide the functionality of diagnosing files in the destination, and exiting with failure status. (usage): Mark -n as deprecated. * src/mv.c: Likewise. * src/copy.h: Add UPDATE_NONE_FAIL definition. * src/system.h (emit_update_parameters_note): Add --update=none-fail description. * doc/coreutils.texi (cp invocation): Likewise. Also mention why -n is deprecated. * tests/mv/update.sh: Add a test case, including precedence with -n and other --update options. * tests/cp/cp-i.sh: Verify that --backup and --update=none{,-fail} are mutually exclusive. * tests/mv/mv-n.sh: Likewise. * NEWS: Mention the new feature. Addresses https://bugs.gnu.org/62572
2024-02-26cp,mv: reinstate that -n exits with success if files skippedPádraig Brady-6/+5
* src/cp.c (main): Adjust so that -n will exit success if skipped files. * src/mv.c (main): Likewise. * doc/coreutils.texi (cp invocation): Adjust the description of -n. * src/system.h (emit_update_parameters_note): Adjust --update=none comparison. * tests/cp/cp-i.sh: Adjust -n exit status checks. * tests/mv/mv-n.sh: Likewise. * NEWS: Mention the change in behavior. Fixes https://bugs.gnu.org/62572
2024-02-22cp: add --keep-directory-symlink optionDaan De Meyer-0/+27
When recursively copying files into OS trees, it often happens that some subdirectory of the source directory is a symlink in the target directory. Currently, cp will fail in that scenario with the error: "cannot overwrite non-directory %s with directory %s" However, we'd like cp in this scenario to follow the destination directory symlink and copy the files into the symlinked directory instead. Let's support this by adding a new option --keep-directory-symlink that makes cp follow destination directory symlinks. We name the option --keep-directory-symlink to keep consistent with tar which has the same option with the same effect. * doc/coreutils.texi (cp invocation): Describe the new option. * src/copy.h: Add the new setting. * src/copy.h: Adjust to follow symlinks if setting enabled. * src/cp.c (usage): Describe the new option. (main): Accept the new option. * tests/cp/keep-directory-symlink.sh: A new test. * tests/local.mk: Reference the new test. * NEWS: Mention the new feature.
2024-01-17tests: make ulimit -v interact better with ASANPádraig Brady-1/+1
ulimit -v is generally not supported with ASAN, giving errors like: "ReserveShadowMemoryRange failed while trying to map 0x... bytes. Perhaps you're using ulimit -v" * tests/cp/link-heap.sh: Mention ASAN as a possible reason for skipping. * tests/csplit/csplit-heap.sh: Likewise. * tests/cut/cut-huge-range.sh: Likewise. * tests/dd/no-allocate.sh: Likewise. * tests/printf/printf-surprise.sh: Likewise. * tests/rm/many-dir-entries-vs-OOM.sh: Likewise. * tests/head/head-c.sh: Only skip the part of the test needing ulimit. * tests/split/line-bytes.sh: Likewise.
2024-01-01maint: update all copyright year number rangesPádraig Brady-63/+63
Update to latest gnulib with new copyright year. Run "make update-copyright" and then... * gnulib: Update included in this commit as copyright years are the only change from the previous gnulib commit. * tests/init.sh: Sync with gnulib to pick up copyright year. * bootstrap: Manually update copyright year, until we fully sync with gnulib at a later stage. * tests/sample-test: Adjust to use the single most recent year.
2023-12-19copy,install: avoid unnecessary security context translationsChristian Göttsche-0/+6
Do not perform SELinux context translation for operations not involving user input or output. Context translation converts MCS/MLS labels into human readable form, which is useful for user facing applications like ls(1) or the --context=CTX argument of cp(1). * src/copy.c (set_process_security_ctx): Use raw selinux variants. * src/install.c (need_copy): Likewise. (setdefaultfilecon): Likewise. * src/selinux.c (computecon): Likewise. (defaultcon): Likewise. * tests/cp/no-ctx.sh: Add raw variants to preload lib. * NEWS: Mention the improvement.
2023-08-28maint: spelling fixes, including author namesPaul Eggert-1/+1
Most of this just affects commentary and documentations. The only significant behavior change is translating author names via proper_name_lite rather than proper_name_utf8, or not translating them at all. proper_name_lite is good enough for coreutils and avoids the bloat that had coreutils not using Gnulib proper_name. * bootstrap.conf (gnulib_modules): Use propername-lite instead of propername. (XGETTEXT_OPTIONS): Look for proper_name_lite instead of for proper_name_utf8. * cfg.mk (local-checks-to-skip): Remove sc_proper_name_utf8_requires_ICONV, since we no longer use proper_name_utf8. (old_NEWS_hash): Update. (sc_check-I18N-AUTHORS): Remove; no longer needed.
2023-08-21cp: with --sparse=never, avoid COW and copy offloadPádraig Brady-0/+5
* src/cp.c (main): Set default reflink mode appropriately with --sparse=never. * src/copy.c (infer_scantype): Add a comment to related code. * tests/cp/sparse-2.sh: Add a test case. * NEWS: Mention the bug.
2023-05-03cp: -p --parents: fix failure to preserve permissions for absolute pathsPádraig Brady-0/+6
* src/cp.c (re_protect): Ensure copy_acl() is passed an absolute path. * tests/cp/cp-parents.sh: Add a test case. * NEWS: Mention the bug. Fixes https://bugs.gnu.org/63245
2023-04-25copy: reduce verbosity of -i and -u with --verbosePádraig Brady-5/+8
Since skipping of files is central to the operation of -i and -u, and with -u one may be updating few files out of many, reinstate the verbosity of this functionality as it was before 9.3. * src/copy.c (copy_internal): Only output "skipped" message with --debug. Also adjust so message never changes with --debug. * tests/cp/cp-i.sh: Adjust accordingly. * tests/mv/mv-n.sh: Likewise. * tests/cp/debug.sh: Add explicit test case for message. * NEWS: Mention the change in behavior.
2023-04-24tests: avoid failure when cp fails for proc filesAndreas Schwab-1/+7
When run under QEmu emulation emulated /proc files have unstable inode numbers. * tests/cp/proc-short-read.sh: Skip if unstable inode numbers detected.
2023-04-13tests: avoid dependence on file layout for cp sparse checkPádraig Brady-14/+4
* tests/cp/sparse-2.sh: Don't depend on the copy taking <= allocation of the source. Instead leverage --debug to check that zero detection is being enabled.
2023-04-10tests: avoid non portable brace expansionPádraig Brady-2/+2
* tests/cp/backup-dir.sh: Avoid non portable brace expansion which is not supported by FreeBSD or Solaris shells at least.
2023-04-08cp,mv: issue "skipped" messages when skipping filesPádraig Brady-5/+12
* NEWS: Mention the change in behavior to issue a "not replaced" error diagnostic with -n, and the "skipped" message with -v. * src/copy.c (copy_internal): Adjust to output the "skipped" messages depending on -i, -n, -u. * tests/cp/cp-i.sh: Adjust accordingly. * tests/mv/mv-n.sh: Likewise.
2023-04-04cp: fix --backup with subdirectoriesPádraig Brady-1/+7
* gnulib: Reference the latest gnulib including the fix to the backupfile module in commit 94496522. * tests/cp/backup-dir.sh: Add a test to ensure we rename appropriately when backing up through subdirs. * NEWS: Mention the bug fix. Fixes https://bugs.gnu.org/62607
2023-03-15test: avoid a test hang on HurdPádraig Brady-1/+1
* tests/cp/sparse-to-pipe.sh: Protect the cp call seen to hang on Hurd/i686 with a timeout. Reported By: Bruno Haible
2023-02-24tests: determine if SEEK_HOLE is enabledPádraig Brady-4/+4
Upcomming gnulib changes may disable SEEK_HOLE even if the system supports it, so dynamically check if we've SEEK_HOLE enabled. * init.cfg (seek_data_capable_): SEEK_DATA may be disabled in the build if the system support is deemed insufficient, so also use `cp --debug` to determine if it's enabled. * tests/cp/sparse-2.sh: Adjust to a more general diagnostic. * tests/cp/sparse-extents-2.sh: Likewise. * tests/cp/sparse-extents.sh: Likewise. * tests/cp/sparse-perf.sh: Likewise.
2023-02-24cp,install,mv: add --debug to explain how a file is copiedPádraig Brady-0/+28
How a file is copied is dependent on the sparseness of the file, what file system it is on, what file system the destination is on, the attributes of the file, and whether they're being copied or not. Also the --reflink and --sparse options directly impact the operation. Given it's hard to reason about the combination of all of the above, the --debug option is useful for users to directly identify if copy offloading, reflinking, or sparse detection are being used. It will also be useful for tests to directly query if these operations are supported. The new output looks as follows: $ src/cp --debug src/cp file.sparse 'src/cp' -> 'file.sparse' copy offload: yes, reflink: unsupported, sparse detection: no $ truncate -s+1M file.sparse $ src/cp --debug file.sparse file.sparse.cp 'file.sparse' -> 'file.sparse.cp' copy offload: yes, reflink: unsupported, sparse detection: SEEK_HOLE $ src/cp --reflink=never --debug file.sparse file.sparse.cp 'file.sparse' -> 'file.sparse.cp' copy offload: avoided, reflink: no, sparse detection: SEEK_HOLE * doc/coreutils.texi (cp invocation): Describe the --debug option. (mv invocation): Likewise. (install invocation): Likewise. * src/copy.h: Add a new DEBUG member to cp_options, to control whether to output debug info or not. * src/copy.c (copy_debug): A new global structure to unconditionally store debug into from the last copy_reg operations. (copy_debug_string, emit_debug): New functions to print debug info. * src/cp.c: if ("--debug") x->debug=true; * src/install.c: Likewise. * src/mv.c: Likewise. * tests/cp/debug.sh: Add a new test. * tests/local.mk: Reference the new test. * NEWS: Mention the new feature.
2023-02-03tests: fix exit status check in cp -u testPádraig Brady-1/+1
* tests/cp/preserve-link.sh: This should have been part of commit v9.1-134-g01503ce73.
2023-01-31cp,mv: skipping due to -u is success, not failurePaul Eggert-2/+2
This reverts the previous change, so that when a file is skipped due to -u, this is not considered a failure. * doc/coreutils.texi: Document this. * src/copy.c (copy_internal): If --update says to skip, treat this as success instead of failure. * tests/mv/update.sh, tests/cp/slink-2-slink.sh: Revert previous change, to match reverted behavior.
2023-01-31cp,ln,mv: when skipping exit with nonzero statusPaul Eggert-8/+8
* NEWS, doc/coreutils.texi: Document this. * src/copy.c (copy_internal): * src/ln.c (do_link): Return false when skipping action due to --interactive or --no-clobber. * tests/cp/cp-i.sh, tests/cp/preserve-link.sh: * tests/cp/slink-2-slink.sh, tests/mv/i-1.pl, tests/mv/i-5.sh: * tests/mv/mv-n.sh, tests/mv/update.sh: Adjust expectations of exit status to match revised behavior.
2023-01-01maint: update all copyright year number rangesPádraig Brady-62/+62
Update to latest gnulib with new copyright year. Run "make update-copyright" and then... * tests/init.sh: Sync with gnulib to pick up copyright year. * bootstrap: Manually update copyright year, until we fully sync with gnulib at a later stage. * tests/sample-test: Adjust to use the single most recent year.
2022-12-29maint: avoid recent syntax check failurePádraig Brady-2/+3
* tests/cp/proc-short-read.sh: Adjust so shorter lines.
2022-12-26tests: accommodate bogomips capitalizationsPaul Eggert-2/+2
* tests/cp/proc-short-read.sh: Kernel on ARMv7 Processor rev 3 (v7l) spells it "BogoMIPS", so allow any capitalization. Patch from Zach van Rijn in <https://bugs.gnu.org/60339>.
2022-04-09cp,mv,install: avoid opening non directory destinationPádraig Brady-7/+5
commit v9.0-66-ge2daa8f79 introduced an issue, for example where cp could hang when overwriting a destination fifo, when it would try to open() the fifo on systems like Solaris 10 that didn't support the O_DIRECTORY flag. This is still racy on such systems, but only in the case where a directory is replaced by a fifo in the small window between stat() and open(). * src/system.h (target_directory_operand): On systems without O_DIRECTORY, ensure the file is a directory before attempting to open(). * tests/cp/special-f.sh: Protect cp with timeout(1), as cp was seen to hang when trying to overwrite an existing fifo. * NEWS: Mention the bug fix.
2022-01-13cp: when copying to dir use dir-relative namesPaul Eggert-1/+9
When copying to a directory, use functions like openat to access the destination files, when such functions are available. This should be more efficient and should avoid some race conditions. * bootstrap.conf (gnulib_modules): Add areadlinkat-with-size, fchmodat, fchownat, mkdirat, mkfifoat, utimensat. * src/copy.c (lchown) [!HAVE_LCHOWN]: * src/copy.c, src/system.h (rpl_mkfifo, mkfifo) [!HAVE_MKFIFO]: Remove. All uses removed. (utimens_symlink): Remove; we shouldn’t have to worry about those obsolete systems any more. All uses replaced by utimensat. * src/copy.c (copy_dir, set_owner, fchmod_or_lchmod, copy_reg) (same_file_ok, writable_destination, overwrite_ok, abandon_move) (create_hard_link, src_is_dst_backup, copy_internal, copy): * src/cp.c (make_dir_parents_private, re_protect): New args for directory-relative names. All uses changed. Continue to pass full names as needed, for diagnostics and for lower-level functions like qset_acl that do not support directory-relative names. * src/copy.c (copy_reg): Prefer readlinkat to lstatat for merely checking whether a file is a symlink, to avoid EOVERFLOW issues. (subst_suffix): New function. (create_hard_link): Accept a null SRC_NAME as meaning that if it is needed it needs to be constructed from SRC_RELNAME, DST_NAME, and DST_RELNAME. (source_is_dst_backup): Use subst_suffix instead of doing it by hand. (copy_internal): Remember and use directory-relative names instead of full names. * src/cp.c (lchown) [!HAVE_LCHOWN]: Remove. All uses removed. (must_be_working_directory): New function. (target_directory_operand): Simply take file name as arg, and return a file descriptor or negative number on failure; open with O_DIRECTORY to obtain any file descriptor. All uses changed. (target_dirfd_valid): New function. (do_copy): Use these new functions to obtain a file descriptor for any target directory, and use directory-relative names for that directory. (main): Omit no-longer-needed stat when --target-directory, as do_copy now does this. * src/ln.c (O_PATHSEARCH): Move from here ... * src/system.h: ... to here. * tests/cp/fail-perm.sh: Adjust to change in diagnostic wording, and add a test for --no-target-directory.
2022-01-02maint: update all copyright year number rangesPádraig Brady-62/+62
Run "make update-copyright" and then... * gnulib: Update to latest with copyright year adjusted. * tests/init.sh: Sync with gnulib to pick up copyright year. * bootstrap: Likewise. * tests/sample-test: Adjust to use the single most recent year.
2021-11-20cp: fix --preserve=ownership permissions bugPaul Eggert-1/+9
This fixes a bug that I introduced in 2006-12-06T19:44:08Z!eggert@cs.ucla.edu. * src/copy.c (USE_XATTR): New macro. (copy_reg): Use it to help the compiler. Prefer open u+w to a later chmod u=rw; u+r isn’t needed for xattr. For the later u-r, do only one (or zero) chmod calls instead of two (or one). In the last chmod, respect the umask instead of ignoring it. * tests/cp/preserve-mode.sh: Test for the bug.
2021-09-25tests: cp/sparse-perf: make more robust and add zfs commentsPádraig Brady-16/+10
* init.cfg (seek_data_capable_): Add a timeout to ensure failure for slow lseek(...SEEK_DATA) calls (even if that syscall isn't interrupted). * tests/cp/sparse-perf.sh: Run the SEEK_DATA check on the 1TiB empty file to exclude both FreeBSD 9.1 which takes 35s, and ZFS which requires a delay of about 5s between file creation and use of SEEK_DATA to correctly determine it's empty (return ENXIO). Also remove the stat size checks as they invalidate the test due to cp never writing data due to it being always zeros, and thus converted to holes in the output.
2021-09-24tests: sparse-perf: avoid false failurePádraig Brady-1/+10
* tests/cp/sparse-perf.sh: Avoid the case where we saw SEEK_DATA take 35s to return a result against a 1TB sparse file. This happened on a FreeBSD 9.1 VM at least. Reported by Nelson H. F. Beebe.
2021-08-25tests: avoid reflinks when testing SEEK_DATA logicPádraig Brady-15/+20
This better tests the SEEK_HOLE logic which replaced the original fiemap hole identification logic. Also it avoids a false failure in sparse-2.sh on reflink supporting file systems, where we try to correlate the file sizes produced by cp and dd. * tests/cp/sparse-2.sh: s/cp/cp --reflink=never/ * tests/cp/sparse-extents-2.sh: Likewise. * tests/cp/sparse-extents.sh: Likewise. * tests/cp/sparse-perf.sh: Likewise. * tests/cp/sparse.sh: Likewise. Fixes https://github.com/coreutils/coreutils/issues/54
2021-07-28doc: modernize usage of “disk” and “core”Paul Eggert-1/+1
In documentation and comments, don’t assume that secondary storage devices are disk devices. Similarly, don’t assume that main memory uses magnetic cores, which became obsolete in the 1970s. * src/du.c (usage): * src/ls.c (usage): * src/shred.c (usage): Reword to avoid “disk” in usage messages.
2021-05-12tests: fix tests/cp/sparse-2.sh false failure on some systemsPádraig Brady-3/+10
* tests/cp/sparse-2.sh: Double check cp --sparse=always, with dd conv=sparse, in the case where the former didn't create a sparse file. Now that this test is being newly run on macos, we're seeing a failure due to seek() not creating holes on apfs unless the size is >= 16MiB.