Skip to content

fix(receiver): remove a non-regular obstacle before a file transfer - #7602

Merged
oferchen merged 4 commits into
masterfrom
fix/obstacle-regular-file-removal
Sep 1, 2026
Merged

oferchen merged 4 commits into
masterfrom
fix/obstacle-regular-file-removal

Conversation

@oferchen

@oferchen oferchen commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #7597

⚠ This branch is stacked on #7597 (fix/obstacle-dir-removal), not on master. Stack: 1faf3c46f -> 0dac95a43 (#7597) -> this PR. #7597 must land first. It created make_way_for_replacement, which owns both of delete_item()'s arms — this PR only routes a sixth call site onto it.

The gap

Upstream removes whatever stands at the destination before it requests the delta for a regular file:

/* generator.c:2148-2153 */
if (statret == 0 && !(stype == FT_REG || (write_devices && stype == FT_DEVICE))) {
        if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_FILE) != 0)
                goto cleanup;
        statret = -1;
        stat_errno = ENOENT;
}

oc had no analogue at that site, so the obstacle survived into the commit. A rename() over a symlink, FIFO, or socket replaces the node by accident — which is why the plain-mode cells for those shapes looked correct — but rename() onto a directory is EISDIR, and there the whole run stopped.

Measured

rsync 3.5.0 (protocol 32) over a real --server child on both ends, source a regular file, obstacle at dst/a, sibling file present, each cell carrying a control that proved the removal was permitted (removable in all cells, so a surviving node means not attempted, never attempted and refused):

obstacle rsync 3.5.0 oc before oc after
empty dir rc=0, <f+++++++++ a, regular file placed rc=12 server error: Is a directory (os error 21), dir kept, sibling unsent rc=0, <f+++++++++ a, regular file placed
non-empty dir rc=23, could not make way for new regular file: a + cannot delete non-empty directory: a, dir kept rc=12, same abort rc=23, both lines, dir kept, sibling written

Both before rows were re-measured on this branch's parent, not quoted from an earlier report. The four symlink/FIFO rows #7597 fixed are unchanged, and the full six-shape sweep (symlink, fifo, regular x empty, non-empty) now matches 3.5.0 in exit code, itemize row, and diagnostic text.

What changed

A routing change, not a second mechanism. make_way_for_replacement already owns the rmdir-with-ENOTEMPTY-refusal arm and the backup-else-unlink arm, and already emits could not make way for %s %s. The regular-file site now calls it with a new DEL_FOR_FILE noun ("regular file", delete.c:276). No removal and no diagnostic is written twice.

The gate is upstream's own test: a destination is kept only when it is already a regular file, or when --write-devices asked for the delta to go straight into an existing device node. On success dest_meta is cleared, which is statret = -1: 3.5.0 itemizes a cleared obstacle <f+++++++++, not as a replacement of the node it displaced.

Proofs

Three independent mutations, each killing exactly one cell:

  1. routing disabled -> both rows redden at 12, reproducing the measured Is a directory (os error 21) text verbatim;
  2. dest_meta = None dropped -> the empty-dir cell reddens on the itemize row alone (<f.sT...... where 3.5.0 prints <f+++++++++);
  3. the gate widened one type, so an ordinary regular destination is unlinked too -> the no-obstacle companion reddens. Bytes alone do not catch that (-I re-sends the file either way, so a delete-then-create still lands the right content at exit 0); the -i row does. The companion was inert against this mutation until it asserted on the row, which is why it now does.

Manifests

No row moves. The 3.5.0 python suite, all 345 cells, nonroot, against this branch's binary: 8 FAIL, of which 6 are exactly the rows tools/ci/upstream-3.5.0-expect.nonroot.txt already names. The other two (daemon-copylinks-parent-escape, daemon-scan-cwd-desync) pass 3/3 when re-run in isolation against the same binary — host contention inside the 25-cell chunk, not a moved row. No manifest is edited.

Residuals, unchanged and out of scope

  • A destination symlink whose target is a regular file, and a dangling destination symlink, are still classified by the candidate pass's follow-stat, so they are renamed over rather than removed and --backup does not see them. Neither can reach the new branch (dest_meta is Some(is_file) / None respectively), so this PR leaves both exactly as they were. Measured: the dangling-symlink-under---backup cell is the one row in that sweep where oc still differs from 3.5.0.
  • --force/DEL_RECURSE stays unreachable while the server arg parser discards --force (cli/src/frontend/server/flags.rs:615).

A directory standing where the receiver has to create a symlink, FIFO,
socket, or device node was neither removed nor reported. oc backed it
up when `--backup` was on, tried a `File`-only unlink when it was off,
discarded the result either way, and routed the failure to a
verbosity-gated `debug_log!`.

Upstream decides this in one place. `atomic_create` sets
`dir_in_the_way` (generator.c:2469), which also forces `skip_atomic`,
so a directory obstacle reaches `delete_item` whether or not `--backup`
is set - the `make_backup` arm is unreachable for it in either mode.
`delete_item` splits the same way one level down: the `rmdir` arm at
delete.c:222-226, the `make_backup`/`unlink` arm in the `else` at
delete.c:227-238.

That is why the removal and the reporting are one change. A guard added
to the backup path could only cover the `--backup`-on half; the four
`--backup`-off shapes below would still be decided in links.rs and
special.rs. And the reporting alone is a regression: with the removal
disabled but the diagnostics in place, a symlink over an EMPTY
directory exits 23 with `delete_file: unlink(obstacle) failed` where
3.5.0 exits 0. Measured by mutation, not argued.

The five `backup_existing_before_replace` call sites in links.rs and
special.rs now share one `make_way_for_replacement`, which owns both
arms and emits upstream's diagnostics itself.

Measured against rsync 3.5.0 (protocol 32) over a real `--server` child
on both ends, `--backup` off:

  src kind | obstacle      | 3.5.0                | oc before
  ---------|---------------|----------------------|---------------------
  symlink  | empty dir     | 0, symlink placed    | 12, dir kept
  symlink  | non-empty dir | 23 + two diagnostics | 12, dir kept
  fifo     | empty dir     | 0, fifo placed       | 0 SILENT, dir kept
  fifo     | non-empty dir | 23 + two diagnostics | 0 SILENT, dir kept

The failing rows also abandoned the rest of the batch: the sibling file
upstream transfers at exit 23 was never written. Both FIFO rows
reported success while losing the node - silent data loss, not a loud
failure. All four now match 3.5.0 in exit code and in text.

Under `--backup` with a sibling backup dir, oc RENAMED the directory
into the backup area, which upstream never does: a wrong-data outcome
at exit 0 that no exit-code assertion could catch. It is now removed.

The full 3.5.0 python suite (345 cells, nonroot) reports exactly the
six failures the expect manifest already names, so no row moves in
either direction and the manifest is unchanged.

Known residual, measured and out of scope: generator.c:2481 sets
`DEL_RECURSE` under `--delete`/`--force`, so upstream removes a
POPULATED directory obstacle recursively and exits 0. `--force` is
parsed and discarded by the server arg parser
(cli/src/frontend/server/flags.rs:615) and has no field in
`ParsedServerFlags`, so the receiver cannot see it. Wiring it is a
server-arg change. The refusal here is still closer to upstream than
the pre-change abort at 12.
The EACCES cross-site note opened with a line-initial dash, so rustdoc -
and `clippy::doc_lazy_continuation` under `-D warnings` - read it as a
list item whose two following lines are lazy continuations. That is a
hard error on the required fmt + clippy gate, raised twice at
munge_symlinks.rs:124-125.

Prose only, and the claim is unchanged: one fail-loud regression per
site is still sufficient because both sites share the same
upstream-parity rule (`PermissionDenied` is the only non-fatal class).
No behaviour, no test, no manifest row moves.

`cargo clippy --workspace --all-targets --all-features -- -D warnings`
is clean with only this hunk applied, and no other file on this branch
carries the same dash-then-continuation shape. A file no `mod`
declaration reaches is never compiled, so it cannot raise this lint
either - unlike a formatting diff, there is no invisible second site.
@oferchen
oferchen force-pushed the fix/obstacle-regular-file-removal branch from d01dcb6 to 47380fc Compare September 1, 2026 11:05
`create_specials` is the only constructor of `MakeWayFor::Device` and
`MakeWayFor::Special`, and it is `#[cfg(unix)]` - Windows has no `mknod`
path. On Windows both variants are therefore unconstructible, and
`dead_code` fires:

    error: variants `Device` and `Special` are never constructed
      --> crates/transfer/src/receiver/directory/obstacle.rs:81:5
    = note: `-D dead-code` implied by `-D warnings`

ci.yml sets `RUSTFLAGS: "-D warnings"` at workflow scope, and the
`windows-test` job runs `cargo nextest run --locked -p transfer
--all-features`, so this is a hard failure of a required cell rather
than a warning.

Reproduced and fixed against a cross-check:
`RUSTFLAGS="-D warnings" cargo check -p transfer --all-targets
--all-features --target x86_64-pc-windows-gnu` errors before and is
clean after. `Symlink` stays ungated - the Windows symlink creator
constructs it.
Upstream removes whatever stands at the destination before it requests
the delta for a regular file:

  generator.c:2147-2152
  if (statret == 0 && !(stype == FT_REG || (write_devices && stype == FT_DEVICE))) {
          if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_FILE) != 0)
                  goto cleanup;
          statret = -1;
          stat_errno = ENOENT;
  }

oc had no analogue at that site, so the obstacle survived into the
commit. A rename over a symlink, FIFO, or socket replaces the node by
accident, which is why the plain-mode cells for those shapes looked
correct; a rename onto a directory is EISDIR, and there the whole run
stopped.

Measured against rsync 3.5.0 (protocol 32) over a real --server child on
both ends, source a regular file, obstacle at dst/a, each cell carrying a
control that proved the removal was permitted:

  obstacle      | 3.5.0                                  | oc before
  --------------|----------------------------------------|-------------------
  empty dir     | 0, `<f+++++++++`, regular file placed   | 12 `server error:
                |                                        |  Is a directory
                |                                        |  (21)`, dir kept
  non-empty dir | 23 + `could not make way for new        | 12, dir kept
                | regular file: a` + `cannot delete       |
                | non-empty directory: a`                 |

Both oc rows also abandoned the batch: the sibling file upstream
transfers was never written.

This is a routing change, not a second mechanism. The previous commit's
`make_way_for_replacement` already owns both of `delete_item`'s arms -
rmdir with the ENOTEMPTY refusal for a directory, backup-if-`--backup`
else unlink for anything else - and already emits `could not make way for
%s %s`. The regular-file site now calls it with a new `DEL_FOR_FILE`
noun; no removal and no diagnostic is written twice.

The gate is upstream's own test: a destination is kept only when it is
already a regular file, or when `--write-devices` asked for the delta to
go straight into an existing device node. On success `dest_meta` is
cleared, which is `statret = -1`: 3.5.0 itemizes a cleared obstacle
`<f+++++++++`, not as a replacement of the node it displaced.

Proofs, all on the receiver path over a real --server child:

  - routing disabled -> both rows redden at 12 with the same
    `Is a directory (os error 21)` text measured above;
  - `dest_meta = None` dropped -> the empty-dir cell reddens on the
    itemize row alone (`<f.sT......` for `<f+++++++++`);
  - the gate widened one type, so an ordinary regular destination is
    unlinked too -> the no-obstacle companion reddens. Bytes alone do not
    catch that, since -I re-sends the file either way; the `-i` row does.

Residual, unchanged and out of scope: a destination symlink whose target
is a regular file is still classified by the candidate pass's follow-stat
and so is renamed over rather than removed, so `--backup` does not see
it. `--force`/DEL_RECURSE stays unreachable while the server arg parser
discards `--force` (cli/src/frontend/server/flags.rs:615).

No row moves in any expect manifest.
@oferchen
oferchen force-pushed the fix/obstacle-regular-file-removal branch from 47380fc to 3f4e5e1 Compare September 1, 2026 11:13
@oferchen
oferchen merged commit 81c1586 into master Sep 1, 2026
71 checks passed
@oferchen
oferchen deleted the fix/obstacle-regular-file-removal branch September 1, 2026 18:20
oferchen added a commit that referenced this pull request Sep 2, 2026
`## [Unreleased]` last covered the #7304-#7522 era. Measured against the 60
most recently merged pull requests, 44 were absent; of the most recent 45,
43 were absent. Nothing from #7574 onward was recorded at all.

Each entry is derived from what the pull request actually landed - the merge
commit and the body - not from its title. Three cases where those differ:

  * #7616 ships far more than the doc-alias correction its body describes:
    the `upstream_version` pin moves to 3.5.0 and `--version` starts naming
    `quic`, `sd-notify`, `vmsplice` and `send_zc`.
  * #7618 also adds the pull-request rustdoc-link job its body says was
    filed separately, which is what closes the master-only-gate recurrence.
  * #7602's squash carries the closed #7597 as its first commit, so the
    directory-obstacle half is recorded under #7602.

#7587 is deliberately not recorded. Its merge commit is empty: the change
had already landed as #7563, which the section already names.

Entries extend the existing Keep a Changelog groups and the bold
sub-groupings. Clusters that are one story carry one entry with several
references: the FERROR_XFER routing and its two-phase drain (#7576, #7581),
the connection-FSM close edge and the accept loop that outlives a session
error (#7579, #7590), the three detaching daemon suites (#7578, #7588,
#7592), the io_uring and SEND_ZC work (#7593, #7600, #7610), the citation
retargets (#7601, #7603, #7604), and the accept-loop pin flake (#7615,
#7620).

Only `## [Unreleased]` is touched; every released section, including the
3.4.4 statements that were correct when written, is byte-identical.
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.

1 participant