summaryrefslogtreecommitdiffstats
path: root/src/test/test-copy.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: fix type of read() return variable at a couple of placesLennart Poettering2024-06-221-6/+6
| | | | | | | | | read() returns ssize_t (i.e. 64bit typically). We assigned it to int variables in some cases (i.e. 32bit typically). Let's not be so sloppy, and not accidentally drop 32bit on the floor. (of course, this is not an issue IRL since we'll not have allocations above 2^32 ever we could read into, but still, let's clean this up)
* ASSERT_STREQ for simple casesIvan Kruglov2024-04-151-9/+9
|
* Introduce ASSERT_OK_ERRNO()Daan De Meyer2024-04-101-7/+7
| | | | | | ASSERT_OK() is for functions that return negative errno. Let's introduce ASSERT_OK_ERRNO() for syscalls that return -1 and store the error in errno.
* test: Various build environment fixesDaan De Meyer2024-04-091-2/+5
| | | | | | | | All bets are off in build chroots, so let's handle more cases of files or executables that might not be available in build chroots. Specifically, these are all fixes to allow the unit tests to run in the opensuse build chroot.
* copy: introduce COPY_VERIFY_LINKED flagYu Watanabe2024-02-151-0/+22
| | | | | If the flag is set, then copy_file() and friends check if the source file still exists when the copy operation finished.
* test: add test for copying symlink with copy_tree_at()Yu Watanabe2024-02-151-0/+37
|
* fs-util: rename xopenat() -> xopanat_full()Yu Watanabe2024-02-151-2/+2
|
* fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLETLennart Poettering2023-10-261-1/+1
| | | | | | | | We use it for more than just pipe() arrays. For example also for socketpair(). Hence let's give it a generic name. Also add EBADF_TRIPLET to mirror this for things like stdin/stdout/stderr arrays, which we use a bunch of times.
* io-util: introduce loop_write_full that takes a timeoutMike Yuan2023-09-071-3/+3
| | | | | Also drop do_poll as the use case is covered by timeout.
* copy: Add support for creating subvolumes to copy_tree_at()Daan De Meyer2023-08-141-7/+7
| | | | | | | The subvolumes set is a set of source inodes similar to how the denylist hashmap contains source inodes as keys. It indicates directories in the source tree that should become subvolumes in the target tree.
* file-io: Fix copying sparse filesMichael A Cassaniti2023-08-111-0/+73
| | | | | | This change makes sure a data copy using copy_bytes() does not exceed the max_bytes value when using COPY_HOLES and max_bytes stops before the next data section.
* copy: Add COPY_LOCK_BSDDaan De Meyer2023-06-151-0/+21
| | | | | | | When making ephemeral copies of files/directories whose cleanup depends on whether they're locked or not, it's necessary to have the lock from the very beginning, so let's support that with a new COPY_LOCK_BSD flag.
* tree-wide: Fix false positives on newer gccDaan De Meyer2023-05-231-6/+6
| | | | | | Recent gcc versions have started to trigger false positive maybe-uninitialized warnings. Let's make sure we initialize variables annotated with _cleanup_ to avoid these.
* test: use _cleanup_ for temp. filesDavid Tardon2023-04-211-20/+8
|
* copy: make copy_bytes() support O_PATH fdsYu Watanabe2023-04-101-1/+1
|
* chase-symlinks: Rename chase_symlinks() to chase()Daan De Meyer2023-03-241-2/+2
| | | | | | | | | Chasing symlinks is a core function that's used in a lot of places so it deservers a less verbose names so let's rename it to chase() and chaseat(). We also slightly change the pattern used for the chaseat() helpers so we get chase_and_openat() and similar.
* copy: Move chattr arguments to full function signaturesDaan De Meyer2023-03-211-5/+5
| | | | | These are almost never used, so let's move them to the _full() functions signatures.
* copy: Support both inode exclusion and contents exclusionDaan De Meyer2023-02-221-2/+2
| | | | | | | | | | | | In some cases, we want to exclude a directory's contents but not the directory itself. In other cases, we want to exclude a directory and its contents. Let's extend the denylist logic in copy.h to support both by changing the denylist from a set to hashmap so we can store the deny type as the value. We also modify the repart ExcludeFiles= option to make use of this. If a directory to exclude ends with a "/", we'll only exclude its contents. Otherwise, we'll exclude the full directory.
* tree-wide: use -EBADF moreYu Watanabe2022-12-201-1/+1
|
* tree-wide: introduce PIPE_EBADF macroYu Watanabe2022-12-201-1/+1
|
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-3/+3
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* Merge pull request #25338 from DaanDeMeyer/at-fixesYu Watanabe2022-11-131-3/+4
|\ | | | | Followups for #24813
| * test-copy: Stop using rm_rf_physical_and_closeDaan De Meyer2022-11-111-3/+4
| | | | | | | | | | | | This cleanup function depends on resolving fd's to paths via /proc which is unreliable so we shouldn't depend on it for destructive operations. Use regular path based cleanup instead.
* | copy: Support passing a deny list of files/directories to not copyDaan De Meyer2022-11-101-8/+20
|/
* Merge pull request #24813 from DaanDeMeyer/at-all-the-thingsLuca Boccassi2022-11-101-34/+22
|\ | | | | Add more openat() style variants for existing stuff
| * test-copy: Rework test_copy_tree_replace_dirs() to use new openat() helpersDaan De Meyer2022-11-091-34/+22
| |
* | basic: rename util.h to logarithm.hZbigniew Jędrzejewski-Szmek2022-11-081-1/+0
|/ | | | | util.h is now about logarithms only, so we can rename it. Many files included util.h for no apparent reason… Those includes are dropped.
* tree-wide: fix typoYu Watanabe2022-08-011-1/+1
|
* copy: Respect COPY_REPLACE flag for copy_treeAlexander Wilson2022-07-271-0/+69
| | | | | - Add a test that asserts that copy_tree on an existing file will fail without COPY_REPLACE - Add a test that asserts that copy_tree with COPY_MERGE and COPY_REPLACE on an existing directory will overwrite files that already exist.
* test-copy: use non-0 data block in copy_holesнаб2022-03-291-1/+2
| | | | | | Some filesystems (e.g. zfs with compression!=off, which is the default configuration) automatically hole-punch all-zero blocks ‒ write a block full of ones instead
* strv: make iterator in STRV_FOREACH() declaread in the loopYu Watanabe2022-03-191-1/+0
| | | | This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
* test: initialize buffer to make Coverity silentYu Watanabe2022-01-271-1/+2
| | | | | | Follow-up for f82f0b993740f4a9a3719c4df7c185411710df2b. Fixes CID#1469119.
* shared: Ensure COPY_HOLES copies trailing holesDaan De Meyer2022-01-261-6/+16
| | | | | | | | | | Previously, files with a hole at the end would get silently truncated which breaks reading journal files. This commit makes sure that holes are punched in existing space and if no more space is available, that we grow the file and the hole by using ftruncate(). The corresponding test is extended to put a hole at the end of the file and we make sure that hole is copied correctly.
* test: fix a copy-and-paste errorYu Watanabe2022-01-181-1/+1
| | | | | | | | Follow-up for 12727c2bc2859995cbd561ffc3d9a4d571202254. Addresses https://github.com/systemd/systemd/pull/22125#discussion_r786358474. Fixes CID#1469023.
* journal: Copy holes when archiving BTRFS journal filesDaan De Meyer2022-01-171-0/+44
| | | | | | | | | | | Previously, the holes we punched earlier would get removed when copying the file. Let's enable the new COPY_HOLES flag to make sure this doesn't happen. In my test, this drops a 800MB btrfs journal (without compression) to 720 MB. Fixes #22087
* test: Use TEST macroJan Janssen2021-11-251-31/+17
| | | | | | | | | This converts to TEST macro where it is trivial. Some additional notable changes: - simplify HAVE_LIBIDN #ifdef in test-dns-domain.c - use saved_argc/saved_argv in test-copy.c, test-path-util.c, test-tmpfiles.c and test-unit-file.c
* tree-wide: use WRITE_STRING_FILE_MKDIR_0755 at more placesLennart Poettering2021-11-161-2/+1
|
* xattr-util: merge various getxattr()/listxattr() helpers into ↵Lennart Poettering2021-10-071-1/+1
| | | | | | | | | | | | | | getxattr_at_malloc() + listxattr_at_malloc() Unfortunately fgetxattr() and flistxattr() don't work via O_PATH fds. Let's thus add fallbacks to go via /proc/self/fd/ in these cases. Also, let's merge all the various flavours we have here into singular implementations that can do everything we need: 1. malloc() loop handling 2. by fd, by path, or combination (i.e. a proper openat() like API) 3. work on O_PATH
* basic: spit out chase_symlinks() from fs-util.[ch] → chase-symlinks.[ch]Lennart Poettering2021-10-051-0/+1
|
* tree-wide: coccinelle fixesFrantisek Sumsal2021-03-181-1/+1
| | | | Another batch of fixes (mostly) generated by Coccinelle.
* tree-wide: use UINT64_MAX or friendsYu Watanabe2021-03-041-8/+8
|
* copy: handle copy_file_range() weirdness on procfs/sysfsLennart Poettering2021-02-261-0/+17
| | | | | | This addresses the issue described in https://lwn.net/Articles/846403/ and makes sure we will be able to stream bytes from procfs/sysfs via copy_bytes() if people ask us to.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* copy: optionally, reproduce hardlinks from source in destinationLennart Poettering2020-09-091-8/+34
| | | | | | | | | | This is useful for duplicating trees that contain hardlinks: we keep track of potential hardlinks and try to reproduce them within the destination tree. (We do not hardlink between source and destination!). This is useful for trees like ostree images which heavily use hardlinks and which are otherwise exploded into separate copies of all files when we duplicate the trees.
* tests: various small fixes for strict systemsTopi Miettinen2020-04-261-3/+3
| | | | | | | | | | | | | | | | | | | | | | Don't assume that 4MB can be allocated from stack since there could be smaller DefaultLimitSTACK= in force, so let's use malloc(). NUL terminate the huge strings by hand, also ensure termination in test_lz4_decompress_partial() and optimize the memset() for the string. Some items in /proc and /etc may not be accessible to poor unprivileged users due to e.g. SELinux, BOFH or both, so check for EACCES and EPERM. /var/tmp may be a symlink to /tmp and then path_compare() will always fail, so let's stick to /tmp like elsewhere. /tmp may be mounted with noexec option and then trying to execute scripts from there would fail. Detect and warn if seccomp is already in use, which could make seccomp test fail if the syscalls are already blocked. Unset $TMPDIR so it will not break specifier tests where %T is assumed to be /tmp and %V /var/tmp.
* test-copy: test that xattrs are properly copiedLennart Poettering2019-11-191-5/+28
|
* basic/fs-util: change CHASE_OPEN flag into a separate output parameterZbigniew Jędrzejewski-Szmek2019-10-241-1/+1
| | | | | | | | | | | | | chase_symlinks() would return negative on error, and either a non-negative status or a non-negative fd when CHASE_OPEN was given. This made the interface quite complicated, because dependning on the flags used, we would get two different "types" of return object. Coverity was always confused by this, and flagged every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it would this that an fd is returned). This patch uses a saparate output parameter, so there is no confusion. (I think it is OK to have functions which return either an error or an fd. It's only returning *either* an fd or a non-fd that is confusing.)
* Merge pull request #13022 from keszybz/coverity-cleanupsLennart Poettering2019-07-121-3/+3
|\ | | | | Coverity cleanups
| * test: minor modernizationZbigniew Jędrzejewski-Szmek2019-07-121-3/+3
| | | | | | | | | | | | | | | | | | Coverity was complaining that read() does not terminate the data. But we did that termination earlier, so covirity is wrong (CID#1402306, CID#1402340). Let's modernize the style a bit nevertheless. (size_t) cast is needed to avoid the warning about comparison, iff the value is not a constant.
* | tree-wide: get rid of strappend()Lennart Poettering2019-07-121-4/+4
|/ | | | | It's a special case of strjoin(), so no need to keep both. In particular as typing strjoin() is even shoert than strappend().