Skip to content

Honor the symbolic link option when copying files - #23

Closed
omrzk wants to merge 1 commit into
troglobit:masterfrom
omrzk:fix/copy-symbolic-links
Closed

omrzk wants to merge 1 commit into
troglobit:masterfrom
omrzk:fix/copy-symbolic-links

Conversation

@omrzk

@omrzk omrzk commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

copyfile(..., LITE_FOPT_COPYFILE_SYM) currently follows the source with stat(), making its symlink branch unreachable. It copies a file link's referent, rejects directory links and cannot recreate dangling links. This also affects rsync()'s single-file copying path.

Inspect the link itself when the option is set, preserve its target text and requested modification time, and retain errors from failed link creation. Stage existing rsync() destination replacements beside the destination and rename them into place, so repeated synchronization updates the link while a failed replacement preserves the existing path. Ordinary copies still follow file links and reject directories.

Validation: the new real-filesystem regression fails on current master and passes with this change. It covers relative file/directory/dangling/self links, directory destinations, existing destination preservation, normal dereferencing, timestamps and the existing rsync() caller, including repeated updates, same-path copying and failed replacements. GCC 13 build and strict ASan/UBSan/LeakSanitizer checks pass. Full make check passes 21 of 22 tests; pidfile cannot write /var/tmp here, with the identical failure reproduced on clean master. make distcheck distributes and passes the new test, then hits the same restriction. Native Clang, Debian packaging, other operating systems and a cross-filesystem movefile() were not tested locally. Recursive rsync()'s existing directory-link traversal is unchanged.

Inspect source links without following them when COPYFILE_SYM is requested, before rejecting directories. This makes the documented option recreate link text instead of copying the referent, including dangling and directory links. Preserve requested link timestamps and report link-creation errors without overwriting the destination. Cover direct calls, destination directories, normal dereferencing and the existing rsync file caller.
@troglobit troglobit closed this in 798d70e Nov 14, 2026
@troglobit

Copy link
Copy Markdown
Owner

Hand merged with fuzz due to unwanted behavioral changes, which are now opt-in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants