irsync 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {irsync-0.1.1 → irsync-0.1.2}/.github/workflows/release.yml +2 -2
- {irsync-0.1.1 → irsync-0.1.2}/PKG-INFO +2 -1
- {irsync-0.1.1 → irsync-0.1.2}/PROGRESS.md +11 -6
- {irsync-0.1.1 → irsync-0.1.2}/README.md +1 -0
- {irsync-0.1.1 → irsync-0.1.2}/docs/design/irsync-architecture.md +42 -11
- irsync-0.1.2/docs/superpowers/specs/2026-11-22-first-run-preview-design.md +181 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/__init__.py +1 -1
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/backup.py +153 -40
- irsync-0.1.2/src/irsync/display.py +59 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/preflight.py +59 -5
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_backup.py +403 -21
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_cli.py +1 -1
- irsync-0.1.2/tests/test_display.py +76 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_preflight.py +45 -1
- {irsync-0.1.1 → irsync-0.1.2}/.github/dependabot.yml +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/.github/workflows/test.yml +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/.gitignore +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/.pre-commit-config.yaml +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/LICENSE +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/RELEASING.md +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/docs/hygiene-notes.md +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/docs/superpowers/plans/2026-07-31-mount-safety.md +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/docs/superpowers/plans/2026-07-31-mount-safety.md.tasks.json +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/docs/superpowers/plans/2026-10-18-hygiene-pass.md +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/docs/superpowers/plans/2026-10-18-hygiene-pass.md.tasks.json +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/docs/superpowers/specs/2026-07-31-mount-safety-design.md +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/pixi.lock +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/pixi.toml +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/pyproject.toml +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/__main__.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/cli.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/diff.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/options.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/paths.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/py.typed +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/replay.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/rsync_runner.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/snapshot.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/src/irsync/statx.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/__init__.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/conftest.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_diff.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_integration.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_main.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_options.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_paths.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_replay.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_rsync_runner.py +0 -0
- {irsync-0.1.1 → irsync-0.1.2}/tests/test_snapshot.py +0 -0
|
@@ -31,5 +31,5 @@ jobs:
|
|
|
31
31
|
with:
|
|
32
32
|
name: dist
|
|
33
33
|
path: dist/
|
|
34
|
-
# Pinned by commit SHA (v1.14.
|
|
35
|
-
- uses: pypa/gh-action-pypi-publish@
|
|
34
|
+
# Pinned by commit SHA (v1.14.3) per supply-chain guidance; Dependabot bumps it.
|
|
35
|
+
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: irsync
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Rename-aware rsync wrapper that uses inode snapshots to skip retransfer of moved files.
|
|
5
5
|
Project-URL: Homepage, https://github.com/killett/irsync
|
|
6
6
|
Project-URL: Repository, https://github.com/killett/irsync
|
|
@@ -239,6 +239,7 @@ the prompt (130).
|
|
|
239
239
|
```
|
|
240
240
|
src/irsync/
|
|
241
241
|
paths.py # is_rsync_remote, ensure_local_dir, with_trailing_slash
|
|
242
|
+
display.py # display_name — file names made safe to print in previews
|
|
242
243
|
snapshot.py # snapshot_tree, write_snapshot, read_snapshot, SNAPSHOT_FILENAME
|
|
243
244
|
statx.py # ctypes statx(2) wrapper — inode birth time (btime)
|
|
244
245
|
preflight.py # mount / empty-source / nonempty-dest / rsync-present guards
|
|
@@ -4,10 +4,11 @@ This file is the session-resume entry point mandated by `CLAUDE.md` — read it
|
|
|
4
4
|
|
|
5
5
|
## Current work
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
7
|
+
- **Merged (2026-11-22): the first-backup summary fix,** fast-forwarded into local `main` from branch `fix-first-run-preview` (deleted), 424 passed and 1 skipped on the merged result, and pushed. The summary compared every source entry at every depth against the destination's top-level names only ("70,995 entries" vs "12 existing entries"), which made an up-to-date backup look nearly empty; the fix also makes names safe to print, after a reproduced crash on a non-UTF-8 file name. Bounded work, so there is no plan document: the approved design is [`docs/superpowers/specs/2026-11-22-first-run-preview-design.md`](docs/superpowers/specs/2026-11-22-first-run-preview-design.md), and its three rules were the task list. **All three are implemented and committed on the branch** (Rule 3 `7f81ad1`, `e59f8ba`, AD-34; Rule 1 `dc1fa59`, `4d47d3b`; Rule 2 `0c1a4c2`; AD-25's text updated), 425 tests. **Releasing as 0.1.2 (2026-11-22), owner-approved:** Dependabot #4 (`pypa/gh-action-pypi-publish` 1.14.2 → 1.14.3; the pinned SHA checked against the signed `v1.14.3` tag) merged locally with `--no-ff` (`f66a97c`) plus its pin comment (`c210d81`), and `main` pushed over HTTPS, which worked because the injected token now carries `workflow` scope. CI on that push failed only on `macos-latest`: the new non-UTF-8 crash test could not create its fixture on APFS (see Gotchas), fixed in `35b91ef` by skipping there. **Next action:** with CI green on the release commit, tag `v0.1.2`, watch the release workflow, verify `pip install irsync==0.1.2` in a clean venv, and create the GitHub Release.
|
|
8
|
+
- **Status:** Maintenance. The 2026-10-18 hygiene pass and the fixes for its three reproduced hazards are merged into local `main`, each a fast-forward on 2026-10-19 with its branch deleted: the empty baseline (`d1bf4c6`), the trash replay (`cd277ea`, AD-32), and one bad drive killing an `ALL` run (`139db1a`, `32e5faf`, AD-33), together with a path escape found while fixing it (`0d32b46`, AD-4; `ec7ab83`, AD-9). All of it is pushed and released as 0.1.1.
|
|
9
|
+
- **Pointer:** the completed plan and task tracker: [`docs/superpowers/plans/2026-10-18-hygiene-pass.md`](docs/superpowers/plans/2026-10-18-hygiene-pass.md) and its `.tasks.json`; what was applied (with commit hashes), found, kept, and counted: the 2026-10-18 entry in [`docs/hygiene-notes.md`](docs/hygiene-notes.md). Architecture, algorithm, all 34 decisions, bug catalog, and invoke examples live in [`docs/design/irsync-architecture.md`](docs/design/irsync-architecture.md).
|
|
10
|
+
- **Next action (maintenance, once the active work above is merged):** Pick the next piece of work from Open questions below; the newest is the stale cross-filesystem symlink refusal, the only reproduced hazard there. The 2026-10-18 audit's last item in Open questions (non-ASCII strings) is an observation, not a reproduced hazard.
|
|
11
|
+
- **Release state:** irsync 0.1.1 (the one-bad-drive and path-escape fixes) was published on 2026-10-22 — tag `v0.1.1` on `74aa092`, CI green on `main` first, the release workflow's build and publish jobs green, and `pip install irsync==0.1.1` verified in a clean venv; a snapshot written by the published 0.1.0 reads cleanly with it. GitHub Release created on 2026-10-23 with hand-written notes describing the path escape (`--generate-notes` had no pull requests to draw on, since these commits went straight to `main`). irsync 0.1.0 was published on 2026-09-06 — tag `v0.1.0` on `724ff49`, PyPI via Trusted Publishing (live, so later releases need no PyPI-side setup), GitHub Release created, and `pip install irsync==0.1.0` verified in a clean venv (it pulls `drivecfg` 0.1.0 from PyPI). conda-forge was deliberately declined: `drivecfg` has no conda-forge package, so submitting irsync would mean writing and co-maintaining a `drivecfg` recipe too; revisit once `drivecfg` is on conda-forge. When this pass started, `main` was at `eed5237` with CI green and no open PRs.
|
|
11
12
|
- **Earlier passes:** what each hygiene pass changed, kept, and reported is recorded per date in [`docs/hygiene-notes.md`](docs/hygiene-notes.md) (2026-07-30, 07-31, 08-01, 09-04, and now 10-18). The broad correctness bug-well looked dry after pass 10, yet audits keep paying: pass 10 found 5 real fixes after pass 9 declared empty; the 2026-10-18 whole-repo audit found 4 bugs, and fixing them surfaced 4 more findings (three reproduced hazards and one observation; see Open questions). All three reproduced hazards among them were fixed on 2026-10-19, and fixing the last one surfaced a fifth finding, a path escape, fixed the same day; see the same hygiene-notes entry.
|
|
12
13
|
|
|
13
14
|
## Cross-cutting decisions
|
|
@@ -38,7 +39,7 @@ One line per architectural decision. The full rationale for every AD lives in [`
|
|
|
38
39
|
- **AD-22** — Dest orphan-tempfile cleanup deferred to just before `apply_moves` to preserve AD-2 (no-change ⇒ no backup-drive access).
|
|
39
40
|
- **AD-23** — `snapshot_tree` walks with an explicit stack (no recursion) to survive very deep trees.
|
|
40
41
|
- **AD-24** — Mount gate checks the first component below `base_dir` (never `base_dir` itself) and runs before the lock, so nothing is written to an unmounted source.
|
|
41
|
-
- **AD-25** — Destination gate fires only with no usable baseline and only for a local dest; a remote dest is reported "not checked"; `UnsafeDestination` is an ALL error, not a skip.
|
|
42
|
+
- **AD-25** — Destination gate fires only with no usable baseline and only for a local dest; a remote dest is reported "not checked"; `UnsafeDestination` is an ALL error, not a skip. The first-run summary and the refusal count both sides at their top level and split the destination's names into kept (excluded), also on the source, and deleted by a real run (2026-11-22).
|
|
42
43
|
- **AD-26** — One override per guard: `--force` (no-change short-circuit) vs `--allow-massive-delete` (>50% guard); both rejected with `--no-snapshot`.
|
|
43
44
|
- **AD-27** — Nested-mount skips produce one aggregated warning per walk (first five paths, then "(and N more)").
|
|
44
45
|
- **AD-28** — An empty source with no baseline is refused whatever the dest holds (`--allow-empty-source`); not `--dry-run`-exempt.
|
|
@@ -47,11 +48,13 @@ One line per architectural decision. The full rationale for every AD lives in [`
|
|
|
47
48
|
- **AD-31** — Drive layout comes from drivecfg, loaded only when `needs_drive_config` says the arguments need it; every shorthand fails closed.
|
|
48
49
|
- **AD-32** — The diff covers only what rsync transfers: rows under an excluded path are dropped from both snapshots, so a move into the trash is a deletion from the backup, never a replayed move.
|
|
49
50
|
- **AD-33** — An `ALL` run survives any one drive's exception: anything unexpected is logged with its traceback and counted as one error; `RsyncUnavailable` still stops the run.
|
|
51
|
+
- **AD-34** — Every name or path placed in preview text goes through `display.display_name` (undecodable bytes as `\xNN`, controls and invisible characters escaped, backslash doubled), so a file name can neither crash the print or the pager nor fake a line.
|
|
50
52
|
|
|
51
53
|
## Gotchas
|
|
52
54
|
|
|
53
55
|
- **The drive layout now comes from `drivecfg`, not from source (2026-08-16).** `src/` contains no drive ids, no `homedir_backup`, no Python-tree path: `Options.from_drive_config` reads them from a `drivecfg.DriveConfig`, and `all_backups` is the config's `backup_order`. The config loads **lazily** — `irsync SRC DEST` on plain paths must keep working with no `drives.toml` anywhere, so `cli.main` only calls `load_config` when `needs_drive_config()` says the arguments need it (or `--config` was passed). That predicate is the single place the rule lives: `ALL` and any single-letter drive id always need a config; **any** source paired with a destination needs none (this is what keeps `irsync '~' /backup` working — `~` is expanded by `Path.expanduser`, never by the config); a source with **no** destination needs one, because it can only be a configured name (including an endpoint's own source path typed out in full, the pre-config alias); and `--snapshot-only` relaxes that last rule, because `resolve_source` falls back to the literal path for a name the config does not know (`cd /mnt && irsync data --snapshot-only`). Under `--snapshot-only` an *absent* config is not an error, but a *broken* one still is. Every shorthand fails closed with exit 2. An unconfigured drive id is now an error rather than resolving under `/media/$USER` — that behaviour change is intentional. `base_dir` keeps its `/media/$USER` default because it is only the mount-gate root: it can refuse a run, never redirect one. `drivecfg` **is on PyPI** (0.1.0), so it installs as an ordinary dependency: `pyproject.toml` declares `drivecfg>=0.1,<1`, `pixi.toml` lists it under `[pypi-dependencies]` with a scoped `[pypi-exclude-newer]` override so the workspace's 7-day supply-chain cooldown doesn't delay a first-party release. The temporary `PYTHONPATH`/`pythonpath` shims pointing at `../drivecfg/src` were deleted in `5b99aee` — do not reintroduce them. What remains is `tests/conftest.py:subprocess_pythonpath()`, which is *not* a shim and stays: a `python -m irsync` subprocess inherits neither pytest's `pythonpath` setting nor pixi's activation, so it needs the repo's `src/` named explicitly.
|
|
54
56
|
- **This file is public** (tracked since 2026-09-04, and the repo is public): keep credential details, machine-specific paths, and anything else you would not publish out of it. The untracked, gitignored `SECURITY-TODO.local.md` is where such notes belong.
|
|
57
|
+
- **macOS APFS refuses file names that are not valid UTF-8** (`OSError` EILSEQ, "Illegal byte sequence"). A test that creates one must catch the `OSError` and skip, as `test_snapshot.py`'s `_make_byte_named_file` does; CI's `macos-latest` job is the only place this shows, and it failed the 2026-11-22 push of `main` before `v0.1.2` was tagged.
|
|
55
58
|
- **Synthesized-row trap:** back any field-semantics test (mtime/ctime/btime/dev) with at least one real syscall test — the 5th-pass ctime gate looked right on fabricated rows but broke on a real rename.
|
|
56
59
|
- **Set/dict iteration non-determinism:** `tmp_path` randomizes hashes, so sampling from a set varies per run — sort before sampling.
|
|
57
60
|
- **`Path.resolve()` follows symlinks:** use `.absolute()` for the symlink itself, `.resolve()` for everything else, when excluding paths from a fuzz plan.
|
|
@@ -75,7 +78,9 @@ One line per architectural decision. The full rationale for every AD lives in [`
|
|
|
75
78
|
|
|
76
79
|
## Open questions
|
|
77
80
|
|
|
78
|
-
- **
|
|
81
|
+
- **Refuse a destination that does not look like this source's backup? (idea, 2026-11-22):** `--allow-nonempty-dest` adopts any non-empty destination on a baseline-less run, so in an `ALL` run with the flag a swapped or wrong backup drive is adopted and `--delete-before` empties it of everything not on the source. The first-run summary's top-level name check (2026-11-22 design) shows the evidence (how many destination top-level names are not on the source) but deliberately does not act on it. A guard could refuse, even with the flag, when most top-level names are not on the source. A new guard needs its own override and tests (AD-26: one override per guard).
|
|
82
|
+
- **Ctrl-C during a real (non-dry-run) backup is unverified (2026-11-22):** a dry run was probed and is safe to interrupt at any point (sources and backups byte-for-byte unchanged, no snapshot written, the next run normal). A probe of the real run was set aside unfinished: after Ctrl-C at 14 points and a rerun to completion, its own "backup matches source" check (`rsync -rcn --delete -i`) reported a mismatch every time, including after an interrupt that landed before rsync started, so the checker itself is the first suspect; it also saw rsync processes still alive the moment irsync exited, which `run_real_sync`'s SIGTERM-then-wait (AD-16) should not leave. Expected by reading the code and not yet confirmed: `-P` implies `--partial`, so an interrupted transfer replaces that one file's old backup copy with a truncated new one until the next run completes it; `--delete-before` deletions already made stay made; the snapshot is not persisted, so the next run is again a first backup (needing `--allow-nonempty-dest`) or replays the same diff.
|
|
83
|
+
- **Non-ASCII in user-facing strings (observation, 2026-10-18; banner resolved 2026-11-22):** the first-run banner in `_format_first_run_preview` had an em dash and, printed under `--yes`, raised `UnicodeEncodeError` on an ASCII-only stdout (`PYTHONIOENCODING=ascii`); the 2026-11-22 rewrite made all of the summary's fixed text ASCII, guarded by a test. File names in it keep their real characters, so a non-ASCII name still cannot print on an ASCII-only stdout. What remains: the `_require_config` message and the `run_backup` permission-denied log line have one too but go through logging to stderr, whose `backslashreplace` error handler escapes it. A C locale still writes UTF-8, so it is mostly theoretical. `--help` is ASCII and guarded by a test. Detail: same hygiene-notes entry.
|
|
79
84
|
- **A stale backup symlink to another filesystem refuses every run (reproduced, 2026-10-19; predates `fix-one-bad-drive`):** if a source symlink whose target is on another filesystem is replaced by a real directory and a file is moved into it, `_preflight_check_xdev` resolves the planned path through the backup's still-stale symlink, sees a different `st_dev`, and raises `CrossDeviceMoveError`, so the run is refused (exit 2) and the next one is refused the same way; nothing is written. Since `ec7ab83`, `apply_moves` skips such a move anyway, so the pre-flight could skip any path that `_through_symlink` flags and let rsync replace the symlink. Probe: target on `/dev/shm`, runs 2 and 3 both exit 2.
|
|
80
85
|
- **chmod/chown-only changes:** mtime doesn't update (only ctime), so `Changes.modified` won't fire and the dest keeps stale permissions — unverified; fix would add mode/uid/gid to `Row` (a snapshot-format change; back any field assumption with a real syscall test).
|
|
81
86
|
- **srsync cron coexistence:** both write the same drives with different lockfiles and could race — migrate fully, or have irsync detect/refuse when an srsync run is active.
|
|
@@ -209,6 +209,7 @@ the prompt (130).
|
|
|
209
209
|
```
|
|
210
210
|
src/irsync/
|
|
211
211
|
paths.py # is_rsync_remote, ensure_local_dir, with_trailing_slash
|
|
212
|
+
display.py # display_name — file names made safe to print in previews
|
|
212
213
|
snapshot.py # snapshot_tree, write_snapshot, read_snapshot, SNAPSHOT_FILENAME
|
|
213
214
|
statx.py # ctypes statx(2) wrapper — inode birth time (btime)
|
|
214
215
|
preflight.py # mount / empty-source / nonempty-dest / rsync-present guards
|
|
@@ -52,18 +52,19 @@ secretly waking the backup drive on every run.
|
|
|
52
52
|
|
|
53
53
|
| Module | Responsibility |
|
|
54
54
|
|---|---|
|
|
55
|
-
| `__init__.py` | `__version__ = "0.1.
|
|
55
|
+
| `__init__.py` | `__version__ = "0.1.2"` |
|
|
56
56
|
| `__main__.py` | `python -m irsync` entry; calls `cli.main()` |
|
|
57
57
|
| `cli.py` | `_build_parser` (argparse: positional `SOURCE` / `DESTINATION`, the safety overrides `--allow-unmounted`, `--require-mount`, `--allow-nonempty-dest`, `--allow-empty-source`, `--allow-massive-delete`, `--force`, the modes `--no-snapshot`, `--snapshot-only`, `--dry-run`, `--yes`, and `--config`, `--ssh-port`, `--ssh-key`, `--no-exclude`, `--debug`, `--version`) and `main`. Rejects `--force` + `--no-snapshot` and `--allow-massive-delete` + `--no-snapshot` at parse time (each flag is a no-op there), and a bad `--ssh-port` / `--ssh-key`. Loads the drive config lazily: only when `needs_drive_config` says the arguments need one, or `--config` is given, or the run is `--snapshot-only` with no destination (the config is consulted in case it names the source, and a discovery that finds none is tolerated); once a load is attempted, a config the arguments require that discovery cannot find, a missing explicit config (`--config`, `$DRIVECFG_CONFIG`) and any broken config are all refused with exit 2, and a plain `irsync SRC DEST` never attempts discovery. Dispatches `ALL` to `run_all_backups`, anything else to `run_backup`, and turns the refusal exceptions into exit 2 |
|
|
58
58
|
| `options.py` | `Options` dataclass (`base_dir`, the mount-gate root, defaulting to `/media/<home-directory name>`; `drive_config`; `exclude_dirs`, defaulting to `.Trash-*`, `.cache`, `unfinished_downloads`; `max_errors`). The layout is never hardcoded: drive ids, named endpoints and the `ALL` order come from a `drivecfg.DriveConfig` via `Options.from_drive_config` (`Options.all_backups` is its `backup_order`), or `Options.without_drive_config` for a plain-path run. `ALL_ARG`; `needs_drive_config` (decides from the argument text alone whether a config is required); `resolve_source` (a source with no destination, for `--snapshot-only`: a configured name wins, otherwise a literal directory); `resolve_endpoints` maps raw CLI args to an `Endpoints` `(source, dest, source_is_remote, dest_is_remote)`. Every shorthand fails closed with `ValueError` when no loaded config defines it |
|
|
59
59
|
| `paths.py` | `is_rsync_remote`, `ensure_local_dir`, `with_trailing_slash` |
|
|
60
|
+
| `display.py` | `display_name`: renders a file name or path so it is safe to print and unambiguous, escaping undecodable bytes, controls, format and separator characters, and backslashes (AD-34) |
|
|
60
61
|
| `snapshot.py` | `snapshot_tree` (iterative walk, `lstat`-based, xdev-aware; raises `FileNotFoundError` / `NotADirectoryError` for a bad root); `Row` TypedDict `(dev, ino, type, nlink, size, mtime_ns, btime_ns, path)` and `Header`; `RowType` / `ROW_TYPES`, the one definition of the row type tags (`f`, `d`, `l`, `o`), used by row validation and by the diff; `write_snapshot`/`read_snapshot` (provenance header + row validation, streaming read, `surrogateescape` encoding; `read_snapshot` still parses the legacy headerless format, whose writer `write_jsonl` and reader `read_jsonl` were removed unused in the 2026-08-01 hygiene pass); shared `_validate_row` helper; `SnapshotMismatch` (the header names a different source root) and `SnapshotCorrupt` (a `ValueError` subclass: a path that is not a regular file, no rows, a malformed or non-object line, a missing key, an unknown type tag, a wrongly typed value, or a malformed path — the whole snapshot is refused rather than partially trusted); reserved-namespace constants `SNAPSHOT_FILENAME = ".irsync_snapshot.jsonl"`, `LOCKFILE_NAME = ".irsync.lock"`, `SNAPSHOT_TEMPFILE_PREFIX = ".irsync-snap-"` and `is_reserved_root_name`, the predicate over them that the snapshot walk and `preflight.py` share |
|
|
61
62
|
| `statx.py` | ctypes wrapper around Linux `statx(2)` for `btime_ns`; returns `-1` when unavailable (non-Linux, no statx, FS without btime, dangling path) so the caller falls back to the size+mtime gate |
|
|
62
63
|
| `diff.py` | `NodeInfo`, `index_by_inode`, `compute_moves` (returns `(dir_moves, file_moves, consumed_keys)`), `prune_redundant_dir_moves`, `plan_directory_moves` (cycle-safe via random temp suffix), `Changes` dataclass `(dir_moves, file_moves, modified, created, deleted)`, `compute_changes` (public API). Move gate: require size + `mtime_ns` match; if both sides have `btime_ns >= 0`, also require `btime_ns` match. `created`/`deleted` filter includes types `l` and `o`; type-change at same path is emitted as both deleted+created |
|
|
63
64
|
| `replay.py` | `apply_moves(dir_moves, file_moves, dest_root) -> ReplayResult`; pure `os.rename`, no-clobber guard, skips a move through a symlinked directory in the backup (`_through_symlink`, AD-9), refuses EXDEV; `CrossDeviceMoveError` + `_preflight_check_xdev` stats every planned src/dst path against `dest_root.st_dev` before any rename runs |
|
|
64
65
|
| `rsync_runner.py` | `build_rsync_command` (anchored excludes for the three reserved-namespace files), `exclude_matcher` (the same exclude list as a path predicate, so the diff leaves out what rsync skips; AD-32), `run_dry_run`, `run_real_sync` (streams stderr live; `start_new_session=True`; routes cancellation through `os.killpg(getpgid(pid), SIGTERM/SIGKILL)` so ssh children die with rsync; installs a scoped SIGTERM handler that raises `KeyboardInterrupt` so cleanup fires on cron timeout) |
|
|
65
66
|
| `backup.py` | Orchestrator: `run_backup` checks that rsync is available (unless `--snapshot-only`), resolves endpoints, runs the mount gates (AD-24, AD-29), acquires `_source_lock` for a local source (AD-8), and dispatches `_run_backup_for_endpoints` / `_run_snapshot_only`; `_run_backup_for_endpoints` runs the snapshot, diff, replay, rsync, persist pipeline and hosts the refusal guards — a corrupt snapshot (`SnapshotCorrupt`, refused per drive with exit 2 — AD-4), the catastrophic-delete ratio (AD-6, `CATASTROPHIC_DELETE_RATIO`), a non-empty destination with no baseline (AD-25), and an empty source with no baseline (AD-28) — and hands `--no-snapshot` or a remote source to `_run_rsync_only`, which always runs the dry-run (so `--no-snapshot --yes` prints to stdout for cron auditability) and honors `--dry-run` (AD-30). Exit codes `EXIT_REFUSED` (2), `EXIT_LOCK_HELD` (75), `EXIT_ABORTED` (130). Previews: `_emit_preview` is the one place that pages when interactive and prints under `--yes` (AD-7), with `_show_preview` / `_format_preview` for a `Changes`, `_format_first_run_preview`, `_dry_run_preview`, and `_page_output` (`less` with `start_new_session=True`); `_confirm_or_abort`. Also `_atomic_write_snapshot` (fsyncs tempfile before `os.replace`), `_persist_snapshots` (dest first, then src — AD-15), `_cleanup_orphan_tempfiles` (scans both src and dest; dest call deferred until `apply_moves` — AD-22), and `run_all_backups` (an unmounted source is a skip; a failing drive, including one refused by a guard such as a corrupt snapshot, counts as one error and the batch carries on, until `max_errors` errors stop it; any other exception from one drive is logged with its traceback and counted the same way, except `RsyncUnavailable` — AD-33). Catches `CrossDeviceMoveError` around `apply_moves` |
|
|
66
|
-
| `preflight.py` | Identity checks that run before irsync writes anything: `mount_gate_root` and `check_mounted` (the mountpoint gate under `base_dir`, with a `role` that raises `SourceNotMounted` or `DestinationNotMounted`, both subclasses of `EndpointNotMounted`; remotes and `base_dir` itself are exempt — AD-24, AD-29); `foreign_dest_entries` (destination-root entries that are not irsync's own, `UnsafeDestination` when the destination cannot be listed — AD-25); `source_root_is_empty` and `fresh_snapshot_is_empty` (the empty-source guard on the `--no-snapshot` and snapshot paths — AD-28); `check_rsync_available` (`RsyncUnavailable`). Reserved-name filtering goes through `snapshot.is_reserved_root_name` |
|
|
67
|
+
| `preflight.py` | Identity checks that run before irsync writes anything: `mount_gate_root` and `check_mounted` (the mountpoint gate under `base_dir`, with a `role` that raises `SourceNotMounted` or `DestinationNotMounted`, both subclasses of `EndpointNotMounted`; remotes and `base_dir` itself are exempt — AD-24, AD-29); `top_level_names` (a root's names, irsync's own left out); `foreign_dest_entries` (destination-root entries that are not irsync's own, `UnsafeDestination` when the destination cannot be listed — AD-25); `split_top_level` / `TopLevelSplit` (a destination's top-level names grouped as kept by rsync's excludes, also on the source, or deleted by a real run — AD-25); `source_root_is_empty` and `fresh_snapshot_is_empty` (the empty-source guard on the `--no-snapshot` and snapshot paths — AD-28); `check_rsync_available` (`RsyncUnavailable`). Reserved-name filtering goes through `snapshot.is_reserved_root_name` |
|
|
67
68
|
|
|
68
69
|
### `tests/`
|
|
69
70
|
|
|
@@ -71,21 +72,22 @@ secretly waking the backup drive on every run.
|
|
|
71
72
|
|---|---|
|
|
72
73
|
| `conftest.py` | Shared fixtures and helpers: `make_tree` (random trees with unique file sizes), `make_options` (factory building `Options` from a tmp_path-rooted drive config), `basic_options` (that factory's defaults), `write_drive_config` (writes a `drives.toml` of invented drive ids under a root), `cli_args` (the argparse `Namespace` the orchestrator expects, with overrides), `subprocess_pythonpath` (the `PYTHONPATH` a `python -m irsync` subprocess needs), `tree_signature`, `inode_for`; the invented ids `DRIVE_IDS`, `SOURCE_DRIVE`, `BACKUP_DRIVE` |
|
|
73
74
|
| `test_paths.py` | path-helper coverage |
|
|
75
|
+
| `test_display.py` | `display_name`: undecodable bytes, ASCII and other controls, format and separator characters, backslash doubling, ordinary names unchanged |
|
|
74
76
|
| `test_snapshot.py` | snapshot round-trip (incl. `SnapshotCorrupt` for malformed or non-object lines, missing keys and invalid types, a file with no rows, wrongly typed values, paths irsync could not have written, a snapshot path that is a directory or FIFO; dotted names still valid; non-UTF-8 round-trip, streaming read, depth-1500 walk) |
|
|
75
77
|
| `test_diff.py` | diff/move detection (incl. symlink add/delete/replace, NFS-sim via real `snapshot_tree` + forged row, real rename, type-"o" add/delete, type-change at same path, real-syscall kernel inode reuse — skips where btime collapses to mtime) |
|
|
76
78
|
| `test_replay.py` | `apply_moves` behavior (incl. moves through a symlinked directory skipped, a symlinked destination root still replayed) |
|
|
77
79
|
| `test_rsync_runner.py` | rsync invocation + subprocess isolation (incl. `start_new_session`, KeyboardInterrupt-during-stream, killpg-on-cancel, SIGTERM handler installed/restored/raises), and `exclude_matcher` checked against what real rsync copies |
|
|
78
80
|
| `test_options.py` | config-backed endpoint resolution (drive ids and named endpoints from an invented-id `drivecfg` config, plain paths, remotes), `Options` without a config, `all_backups` from `backup_order`, `needs_drive_config`'s rules, `resolve_source` |
|
|
79
|
-
| `test_preflight.py` | pre-flight identity checks: `mount_gate_root`, `check_mounted` (exemptions, `role`-specific exceptions), `foreign_dest_entries`, `source_root_is_empty`, `fresh_snapshot_is_empty`, `check_rsync_available` |
|
|
81
|
+
| `test_preflight.py` | pre-flight identity checks: `mount_gate_root`, `check_mounted` (exemptions, `role`-specific exceptions), `foreign_dest_entries`, `split_top_level` (exclude-first grouping, `--no-exclude`, exact name matching), `source_root_is_empty`, `fresh_snapshot_is_empty`, `check_rsync_available` |
|
|
80
82
|
| `test_cli.py` | end-to-end `python -m irsync` runs plus in-process `main` calls: flag validation (incl. parse-time rejection of `--force --no-snapshot` and `--allow-massive-delete --no-snapshot`), lazy config loading (no config for plain paths, `--config`, `--snapshot-only` fallbacks, broken-config refusals), and help text |
|
|
81
83
|
| `test_main.py` | `python -m irsync` exit-code propagation: a stubbed `main` return value becomes the process exit status, and an unstubbed held-lock run exits 75 |
|
|
82
84
|
| `test_backup.py` | orchestrator coverage (incl. persist ordering, dest orphan cleanup, pager session detachment, dest-untouched-on-no-change, fsync-before-replace ordering, a corrupt snapshot refusing only its own drive, a snapshot path outside the tree refused with files outside the backup untouched, a source symlink replaced by a directory writing nothing outside the backup, an `ALL` run surviving a bad snapshot or an unexpected per-drive error while missing rsync still stops it, excluded paths left out of the diff: trash moves, restores, an emptied trash, `--no-exclude`) |
|
|
83
85
|
| `test_integration.py` | 4 end-to-end tests: umbrella exercising every reproducible bug from passes 1-7 + symlink add/delete + 8 random fuzz moves; cross-device refusal via real preflight; isolated H1 symlink add/delete regression net; `--no-snapshot --yes` audit-trail invariant. Pickers use the 10-attempt no-op retry loops from `make_random_moves.py` |
|
|
84
86
|
|
|
85
|
-
Total:
|
|
86
|
-
at the pass-10 migration). One of them, the kernel
|
|
87
|
-
skips where btime collapses to mtime (e.g. tmpfs), so
|
|
88
|
-
|
|
87
|
+
Total: 425 tests as of 2026-11-22 (381 on 2026-10-19, 337 at the 2026-10-18
|
|
88
|
+
hygiene pass, 168 at the pass-10 migration). One of them, the kernel
|
|
89
|
+
inode-reuse btime test, skips where btime collapses to mtime (e.g. tmpfs), so
|
|
90
|
+
a run reports either 425 passed or 424 passed, 1 skipped.
|
|
89
91
|
|
|
90
92
|
## Architectural decisions
|
|
91
93
|
|
|
@@ -439,10 +441,23 @@ always exempt — there is no local mount to check.
|
|
|
439
441
|
`_run_backup_for_endpoints` calls `foreign_dest_entries` only when there is no
|
|
440
442
|
usable baseline (no snapshot, or one rejected by the provenance check), and
|
|
441
443
|
only for a **local** destination — a remote one is never scanned. The
|
|
442
|
-
first-run summary (`_format_first_run_preview`) reports a remote destination
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
444
|
+
first-run summary (`_format_first_run_preview`) reports a remote destination
|
|
445
|
+
as "not checked (remote)", with no counts: it was never scanned, and
|
|
446
|
+
presenting an unchecked 0 as fact would be worse than saying so.
|
|
447
|
+
|
|
448
|
+
Since 2026-11-22 the summary counts both sides the same way, at their top
|
|
449
|
+
level (`top_level_names`, irsync's reserved names left out), and splits the
|
|
450
|
+
destination's top-level names with `split_top_level` into those also on the
|
|
451
|
+
source, those matching rsync's excludes (kept: rsync never deletes an
|
|
452
|
+
excluded name on the receiving side, as irsync passes no
|
|
453
|
+
`--delete-excluded`), and those a real run deletes. It used to set the
|
|
454
|
+
source's every snapshot row beside the destination's top-level count, so an
|
|
455
|
+
up-to-date backup of the right drive read "70,995 entries" against "12
|
|
456
|
+
existing entries" and looked nearly empty. The refusal before
|
|
457
|
+
`--allow-nonempty-dest` reports the same split. No tree is scanned for
|
|
458
|
+
either beyond the two root listings; the gate's condition is unchanged, and
|
|
459
|
+
still refuses on any non-reserved name, an excluded one included.
|
|
460
|
+
`run_all_backups` treats `EndpointNotMounted` as a skip (exit 0
|
|
446
461
|
still possible) but `UnsafeDestination` (destination exists but can't be read)
|
|
447
462
|
as a real error: counted, batch continues to the remaining drives, run exits 1.
|
|
448
463
|
These are deliberately different outcomes for deliberately different failure
|
|
@@ -601,6 +616,22 @@ exit 2 rather than a traceback per drive. The catch-all is a backstop, not
|
|
|
601
616
|
the place to handle a known failure: a known one still gets its own clean
|
|
602
617
|
refusal, as corrupt snapshots do (AD-4).
|
|
603
618
|
|
|
619
|
+
### 34. Every name or path in preview text goes through `display_name`
|
|
620
|
+
|
|
621
|
+
A file name is arbitrary bytes. `os.fsdecode` turns a byte that is not valid
|
|
622
|
+
UTF-8 into a lone surrogate, which a strict UTF-8 stdout (`--yes`) and the
|
|
623
|
+
text pipe to `less` (interactive) both refuse to encode. Reproduced
|
|
624
|
+
2026-11-22: once a file whose name held the byte 0xff was moved, every later
|
|
625
|
+
`--yes` run of that source logged "surrogates not allowed" and exited 2
|
|
626
|
+
before rsync. A name can also hold a newline or a terminal escape that fakes
|
|
627
|
+
or restyles a preview line. `display.display_name` renders a name so neither
|
|
628
|
+
can happen: the original byte as `\xNN`, a control, format, surrogate, or
|
|
629
|
+
line/paragraph-separator code point as `\xNN` (below U+0080), `\uXXXX`, or
|
|
630
|
+
`\UXXXXXXXX`, and a backslash as `\\`, so an escape in the output can only
|
|
631
|
+
have come from it. Every other character, accented and non-Latin text
|
|
632
|
+
included, is printed as is. `_format_preview`, the first-run summary, and the
|
|
633
|
+
`--allow-nonempty-dest` refusal all use it; new preview text must too.
|
|
634
|
+
|
|
604
635
|
## Appendix A — bug catalog
|
|
605
636
|
|
|
606
637
|
28 bugs fixed across 10 review passes (passes 1-8 plus pass 10; pass 9 was
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Design: a first-backup summary that compares like with like
|
|
2
|
+
|
|
3
|
+
Date: 2026-11-22
|
|
4
|
+
Status: approved (brainstorm), not yet implemented
|
|
5
|
+
|
|
6
|
+
## Problem
|
|
7
|
+
|
|
8
|
+
When a backup has no usable snapshot, irsync shows a first-run summary before
|
|
9
|
+
the confirmation prompt (mount-safety spec, Rule 3):
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
=== FIRST BACKUP — no prior snapshot ===
|
|
13
|
+
Source: /media/u/F 70,995 entries, 20.0 TiB
|
|
14
|
+
Destination: /media/u/F_backup 12 existing entries
|
|
15
|
+
rsync will transfer the source in full and DELETE anything at the
|
|
16
|
+
destination that is not on the source.
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The two counts measure different things. The source figure is every row of
|
|
20
|
+
the fresh snapshot, at every depth, including the root itself. The
|
|
21
|
+
destination figure is the number of names directly under the destination
|
|
22
|
+
root, from the same `iterdir` the destination gate performs. Side by side
|
|
23
|
+
they read as "the backup holds 12 of 70,995 entries", which makes an
|
|
24
|
+
up-to-date backup of the right drive look nearly empty. A user stopped at
|
|
25
|
+
exactly this prompt, frightened, and had to verify by hand (top-level `ls`
|
|
26
|
+
of both drives, `df`, and a full `--dry-run`) that the backup was in fact
|
|
27
|
+
identical.
|
|
28
|
+
|
|
29
|
+
The closing sentence adds to it: "transfer the source in full" is wrong
|
|
30
|
+
whenever the destination already holds a backup, because rsync copies only
|
|
31
|
+
what differs.
|
|
32
|
+
|
|
33
|
+
The refusal that precedes `--allow-nonempty-dest` has the same flaw ("already
|
|
34
|
+
contains 12 entries ... rsync would DELETE them"): it counts top-level names
|
|
35
|
+
without saying so, and claims every one of them would be deleted.
|
|
36
|
+
|
|
37
|
+
A related defect sits on the same output path and was reproduced while
|
|
38
|
+
designing this: a file name that is not valid UTF-8 (os.fsdecode turns each
|
|
39
|
+
bad byte into a lone surrogate) crashes the change preview. Under `--yes` with
|
|
40
|
+
a strict UTF-8 stdout, a run in which such a file was moved logs
|
|
41
|
+
`'utf-8' codec can't encode character '\udcff' ... surrogates not allowed`
|
|
42
|
+
and exits 2 before rsync, so that drive can never be backed up until the
|
|
43
|
+
name changes. Interactively, the same text crashes when piped to `less`,
|
|
44
|
+
which `subprocess.Popen(..., text=True)` always encodes strictly.
|
|
45
|
+
|
|
46
|
+
## Decision
|
|
47
|
+
|
|
48
|
+
Make the summary compare like with like, add a cheap name check that tells
|
|
49
|
+
whether the destination looks like this source's backup, and make every name
|
|
50
|
+
that reaches a preview safe to print. No additional scan of either tree: the
|
|
51
|
+
mount-safety spec's "no additional tree scan" rule stands.
|
|
52
|
+
|
|
53
|
+
Alternatives considered:
|
|
54
|
+
|
|
55
|
+
- **Wording only** (label the destination figure "top-level items"). Smallest
|
|
56
|
+
change, but it would not have told the user whether `F_backup` was the right
|
|
57
|
+
backup.
|
|
58
|
+
- **Also run an rsync dry run before the prompt** and print its delete/copy
|
|
59
|
+
counts. The definitive answer, but every first backup, including `--yes`
|
|
60
|
+
runs, would pay a full comparison of both trees first, and parsing
|
|
61
|
+
`--stats` output ties irsync to rsync's wording. The summary points to
|
|
62
|
+
`--dry-run` instead.
|
|
63
|
+
|
|
64
|
+
## Rule 1: the first-run summary
|
|
65
|
+
|
|
66
|
+
For a local destination:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
=== FIRST BACKUP (no usable snapshot) ===
|
|
70
|
+
Source: /media/u/F
|
|
71
|
+
11 top-level items
|
|
72
|
+
70,994 files and folders in all, 20.0 TiB
|
|
73
|
+
Destination: /media/u/F_backup
|
|
74
|
+
12 top-level items:
|
|
75
|
+
11 also on the source
|
|
76
|
+
1 skipped by rsync, so kept: .Trash-1000
|
|
77
|
+
0 not on the source (a real run DELETES these)
|
|
78
|
+
A real run makes the destination match the source: it copies
|
|
79
|
+
whatever differs and DELETES anything there that is not on the source.
|
|
80
|
+
For the exact list of files, answer N and rerun with --dry-run.
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- **Source top-level count** comes from one listing of the source root, with
|
|
84
|
+
irsync's reserved names left out, the same rule the destination listing
|
|
85
|
+
uses (AD-5). A real listing rather than the snapshot rows, because the
|
|
86
|
+
snapshot skips nested mount points (AD-27) while the top-level directory
|
|
87
|
+
of one is still there.
|
|
88
|
+
- **"files and folders in all"** is the snapshot's row count minus the root
|
|
89
|
+
row (`path == "."`), so it counts what is on the drive, not the drive
|
|
90
|
+
itself. The size is unchanged: the sum of regular-file sizes.
|
|
91
|
+
- **Destination split.** Each top-level destination name falls in exactly one
|
|
92
|
+
group, tested in this order:
|
|
93
|
+
1. *skipped by rsync, so kept* — it matches rsync's excludes (the same
|
|
94
|
+
`exclude_matcher` predicate the diff uses, AD-32, built from an empty
|
|
95
|
+
list under `--no-exclude`). rsync never deletes an excluded name on the
|
|
96
|
+
receiving side, since irsync does not pass `--delete-excluded`.
|
|
97
|
+
2. *also on the source* — the source's top level has the same name. The
|
|
98
|
+
comparison is exact, as rsync's is: `Films` vs `films`, or the same
|
|
99
|
+
text in two Unicode normalization forms, are different names.
|
|
100
|
+
3. *not on the source* — a real run deletes it.
|
|
101
|
+
|
|
102
|
+
All three lines are always shown. The second and third name their items,
|
|
103
|
+
sorted, up to ten, then `(and N more)`. Counts are right-aligned in a
|
|
104
|
+
column and use thousands separators.
|
|
105
|
+
- **Other destination states.** A destination that does not exist yet reads
|
|
106
|
+
`does not exist yet (rsync will create it)`. One that exists but holds
|
|
107
|
+
nothing besides irsync's own files reads `empty`. A remote destination
|
|
108
|
+
still reads `not checked (remote)` and has no split; it is never listed
|
|
109
|
+
(AD-25).
|
|
110
|
+
- **Closing sentence.** "A real run makes the destination match the source"
|
|
111
|
+
is true for a real run and for a `--dry-run` preview alike.
|
|
112
|
+
- **The `--dry-run` hint** appears only when there is a prompt to answer:
|
|
113
|
+
not under `--yes`, and not under `--dry-run`, which shows rsync's own
|
|
114
|
+
output right after.
|
|
115
|
+
- **Banner** `=== FIRST BACKUP (no usable snapshot) ===` covers both a
|
|
116
|
+
missing snapshot and one rejected for belonging to another source; the
|
|
117
|
+
existing log line still says which.
|
|
118
|
+
- **Singular and plural.** `1 top-level item`, `2 top-level items`;
|
|
119
|
+
`1 file or folder in all`, `2 files and folders in all`.
|
|
120
|
+
- **ASCII.** Every fixed string in the summary is ASCII. This removes the em
|
|
121
|
+
dash noted in PROGRESS.md's open question about non-ASCII strings, the only
|
|
122
|
+
instance of that problem that could raise rather than be escaped. Names
|
|
123
|
+
keep their real characters apart from Rule 3's escapes.
|
|
124
|
+
|
|
125
|
+
## Rule 2: the refusal before `--allow-nonempty-dest`
|
|
126
|
+
|
|
127
|
+
The destination gate's condition is unchanged: no usable baseline and any
|
|
128
|
+
non-reserved top-level name at a local destination, excluded names included,
|
|
129
|
+
refuses unless `--allow-nonempty-dest`. Only the message changes:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
Refusing: no usable snapshot, but the destination /media/u/F_backup already
|
|
133
|
+
holds 12 top-level items (11 also on the source, 1 skipped by rsync so kept,
|
|
134
|
+
0 not on the source). A first backup makes the destination match the source
|
|
135
|
+
and DELETES anything there that is not on the source. Check that the source
|
|
136
|
+
drive is mounted and that this is its backup, then pass --allow-nonempty-dest
|
|
137
|
+
to adopt it.
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
When the third group is not empty, its names follow, up to ten, then
|
|
141
|
+
`(and N more)`, with the same wording as the summary.
|
|
142
|
+
|
|
143
|
+
## Rule 3: names are made safe before they reach a preview
|
|
144
|
+
|
|
145
|
+
One helper renders a file name or path for display, and every name or path
|
|
146
|
+
placed in preview text goes through it: the first-run summary, the refusal,
|
|
147
|
+
and the existing change preview (`_format_preview`: moves, modifications,
|
|
148
|
+
creations, deletions). It escapes, unambiguously:
|
|
149
|
+
|
|
150
|
+
- a byte that was not valid UTF-8 (a lone surrogate U+DC80–U+DCFF from
|
|
151
|
+
`surrogateescape`) as `\xNN`, the original byte;
|
|
152
|
+
- a control character below U+0080 (C0 and DEL) as `\n`, `\r`, `\t`, or
|
|
153
|
+
`\xNN`. Such bytes are always valid UTF-8, so `\xNN` below `\x80` can
|
|
154
|
+
only mean the character, never a raw byte;
|
|
155
|
+
- any other control, format, separator, or surrogate code point (Unicode
|
|
156
|
+
categories Cc, Cf, Cs, Zl, Zp; this covers C1 controls, bidi overrides,
|
|
157
|
+
and U+2028/U+2029) as `\uXXXX`;
|
|
158
|
+
- a backslash as `\\`, so an escape in the output can only have come from
|
|
159
|
+
this helper.
|
|
160
|
+
|
|
161
|
+
Every other character is printed as is. A name can then neither crash the
|
|
162
|
+
preview nor fake a line in it.
|
|
163
|
+
|
|
164
|
+
## Not changing
|
|
165
|
+
|
|
166
|
+
- The destination gate's condition (Rule 2).
|
|
167
|
+
- Refusing a destination whose names mostly are not on the source even with
|
|
168
|
+
`--allow-nonempty-dest`. That would be a new guard; it is recorded as an
|
|
169
|
+
open question in PROGRESS.md.
|
|
170
|
+
- The source size, which still counts excluded content.
|
|
171
|
+
|
|
172
|
+
## Testing
|
|
173
|
+
|
|
174
|
+
Red/green TDD, a test per rule and per edge case: the like-with-like counts,
|
|
175
|
+
each split group (excluded, `--no-exclude`, on-source, not-on-source),
|
|
176
|
+
the ten-name cap, a missing, an empty, and a remote destination, singular
|
|
177
|
+
and plural, the hint's three modes, ASCII-only fixed text, the refusal
|
|
178
|
+
wording, and the display helper's escapes. The non-UTF-8 tests create real
|
|
179
|
+
files with bad bytes (PROGRESS.md's synthesized-row trap) and run under a
|
|
180
|
+
strict UTF-8 stdout; one end-to-end test runs irsync on real directories and
|
|
181
|
+
checks the printed summary.
|