Skip to content

Enhance file synchronization with tombstone management and renaming fixes - #22

Merged
guydols merged 5 commits into
mainfrom
dev
Sep 16, 2026
Merged

guydols merged 5 commits into
mainfrom
dev

Conversation

@guydols

@guydols guydols commented Sep 16, 2026

Copy link
Copy Markdown
Owner

This pull request significantly strengthens the handling of file and directory deletions (tombstones) and resurrection protection in the file sync engine, ensuring that deleted directories correctly prevent stale or unintended child files from being resurrected. The changes introduce a "covering tombstone" concept, improve the logic for filtering out stale files on both client and server, and add robust tests to guarantee correctness. Additionally, the restoration process from trash now properly clears covering tombstones to allow legitimate restores.

Tombstone Handling and Resurrection Protection:

  • Added the concept of "covering tombstones" in DeletionLedger, allowing the system to detect when a file or directory (or any ancestor) has been deleted and to veto uploads or downloads of stale children accordingly. (covering_tombstone and has_newer_than_prefix methods, plus extensive tests) [1] [2]
  • Updated client and server send paths (send_paths_to_server, broadcast_paths) to filter out files and directories that are covered by a newer tombstone, logging vetoes and preventing resurrection of deleted content. [1] [2]
  • Improved the bundle receive path (handle_recv_bundle) to defensively filter out files covered by tombstones before applying changes, preventing stale retransmissions from resurrecting deleted files.

Protocol and Manifest Logic Improvements:

  • Enhanced the logic in filter_resurrected and its documentation to handle both exact and covering tombstones, ensuring correct behavior for directory deletes and their children. Added comprehensive tests for these scenarios. [1] [2] [3] [4]
  • Refactored tombstone timestamp handling so that a single timestamp is used for both the ledger and wire protocol, avoiding inconsistencies between local and remote delete records. [1] [2] [3] [4] [5]

Restore and Trash Handling:

  • Improved restore_trash_entry to clear all tombstones covering the restored path, ensuring that legitimate restores are not immediately vetoed by prior deletes.

These changes collectively make the sync engine more robust against accidental resurrection of deleted files and directories, and ensure that legitimate recreations and restores work as expected.

Dir deletes tombstone only the top path, so children resurrected via
exact-match checks. Add nearest-ancestor lookup plus has_newer_than_prefix
so a parent delete covers stale children while newer-mtime recreates still win.
filter_resurrected only checked exact paths, so files under a deleted
dir were re-uploaded as new. Fall back to ancestor tombstones for
children (timestamp-only) while keeping hash/mtime checks for exact
paths, so stale subtrees stay deleted and legitimate recreates win.
Moved-in subtrees stayed unwatched and wd->path entries kept pointing
at the old location, so events inside a moved dir were mis-attributed
to the old path and recreated phantom folders. Recursively watch
CREATE/MOVED_TO dirs, rewrite wd_map prefixes on rename, drop stale
watches on IGNORED/MOVE_SELF/DELETE_SELF, and extend move pairing to 2s.
apply_rename moved only the top manifest entry, leaving children on
the old path so scans recreated the source dir. Remap the full subtree
component-wise, suppress all remapped keys, and make missing-src with
present-dst converge instead of erroring. Veto bundle/large-file writes
covered by a newer tombstone, lift tombstones on newer-mtime recreates,
and clear prefix tombstones on trash restore. Document why Rename keeps
no move_id for bincode compat.
Flushes stamped ledger and wire deletes with two now_ms calls so peers
disagreed on LWW winners. Reuse one batch stamp, propagate sender
stamps on forward, prune fabricated ancestor deletes, suppress rename
subtrees recursively, and veto outgoing paths covered by a newer
tombstone before streaming or broadcasting.
@guydols
guydols merged commit 7a70ba9 into main Sep 16, 2026
1 check passed
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