Skip to content

rrsync: fix uploads to existing file destinations - #1136

Open
sairex53 wants to merge 1 commit into
RsyncProject:masterfrom
sairex53:fix-1107-rrsync-existing-file
Open

sairex53 wants to merge 1 commit into
RsyncProject:masterfrom
sairex53:fix-1107-rrsync-existing-file

Conversation

@sairex53

Copy link
Copy Markdown

Fixes #1107.

An upload to an existing file fails because rsync sees the destination's /proc/self/fd/N as a symlink and tries to replace it. Pass the filename beneath a pinned parent directory instead, matching the handling of new files. Existing directory arguments keep their current handling.

This follows the parent-pin approach suggested by @JeanFrancoisGagne in the issue. It reuses pin_dir() and checks that the leaf under the held parent still matches the validated inode.

Added an end-to-end regression test covering existing-file overwrite and new-file creation (normal and --inplace), directories, pulls, rejected .. and symlink paths, a leaf replaced with a symlink during --inplace, and a renamed parent. All test fixtures stay in the test scratch directory.

Testing

On Fedora 44 aarch64:

  • The new test fails before the fix with unlink(3) failed: Operation not permitted and passes after it.
  • All 23 rrsync-* tests pass.
  • Full test suite: 274 passed, 99 skipped, no failures. Skips include tests requiring root, unavailable optional features, TCP transport or an older peer.
  • Python syntax checks and git diff --check pass.

AI assistance: OpenAI Codex.

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small test nitpick but other then that, looks quite good; thank you.

parent.symlink_to(outside, target_is_directory=True)


if gated_transfer('raced-parent/untouched', replace_parent) != 0:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires held-directory traversal to keep working after a rename. Accept either a successful write to saved-parent or a failed transfer with the outside marker unchanged.

Passing an existing destination as the leaf's /proc/self/fd/N makes
rsync lstat the procfs link and try to replace it, failing with EPERM.
Use the held parent fd plus the leaf name, as for a missing destination.
Keep directory arguments pinned directly and verify the parent's leaf
still matches the already validated inode before releasing its fd.

Reuse pin_dir() for the parent checks and execute-only directory support.
Add end-to-end coverage for overwrite, creation, directories, pulls,
rejected paths, an in-place leaf replacement and a parent rename.

Based on the parent-pin approach described by JeanFrancoisGagne in RsyncProject#1107.

Fixes RsyncProject#1107.
Assisted-by: OpenAI Codex
Signed-off-by: Eduard Zateev <hackerowskiy@gmail.com>
@sairex53
sairex53 force-pushed the fix-1107-rrsync-existing-file branch from 442a4ed to e62b5ad Compare October 21, 2026 11:40
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.

rrsync (3.5.x): receiver push onto an existing file always fails (dest passed as bare /proc/self/fd/N)

2 participants