Skip to content

Implement conflict renaming logic#10

Merged
Menelion merged 5 commits into
masterfrom
claude/resolve-todo-comment-011CUqUFmmxPGzYxNGWA2t6H
Nov 5, 2025
Merged

Implement conflict renaming logic#10
Menelion merged 5 commits into
masterfrom
claude/resolve-todo-comment-011CUqUFmmxPGzYxNGWA2t6H

Conversation

@Menelion

@Menelion Menelion commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

No description provided.

Implemented the TODO comments for RenameLocal and RenameRemote conflict
resolution strategies in SyncEngine.cs:

- Added GenerateConflictName() helper method that creates conflict filenames
  with timestamps (e.g., "document.txt" -> "document (conflict 2025-11-05 12-34-56).txt")

- RenameLocal: Moves the local file to a conflict name, then downloads the
  remote file to the original path

- RenameRemote: Moves the remote file to a conflict name, then uploads the
  local file to the original path

Both implementations:
- Check that both local and remote items exist before proceeding
- Use the existing MoveAsync() method from ISyncStorage for efficient renaming
- Fallback to incrementing files conflicted if items are missing
- Properly use existing UploadFileAsync/DownloadFileAsync methods to maintain
  consistency with other sync operations
Enhanced the rename conflict resolution logic to properly track the newly
created conflict files in the sync database:

RenameLocal case:
- After moving local file to conflict name and downloading remote file,
  the conflict file is tracked in the database with status LocalNew
- This ensures the conflict file will be uploaded to remote on next sync

RenameRemote case:
- After moving remote file to conflict name and uploading local file,
  the conflict file is tracked in the database with status RemoteNew
- This ensures the conflict file will be downloaded to local on next sync

Benefits:
- Conflict files are immediately tracked in the database
- Next sync will properly handle these files (upload LocalNew, download RemoteNew)
- Database state accurately reflects the actual file system state
- No orphaned files that aren't tracked
Changed conflict file naming from timestamps to computer/domain names
for better identification of file sources:

- RenameLocal: Uses Environment.MachineName for conflict files
  Example: "document.txt" -> "document (andre-vivobook).txt"

- RenameRemote: Uses domain name extracted from remote storage URL
  Example: "document.txt" -> "document (disk.cx).txt"

Added GetDomainFromUrl() helper method to extract domain from URLs
with fallback to "remote" if URL parsing fails.

Benefits:
- Users can immediately identify which machine/server each version came from
- More intuitive than timestamps for multi-device synchronization
- Clearer conflict resolution for users managing files across devices
- Aligns with common sync tools like Nextcloud, Dropbox, etc.
Enhanced conflict file naming to handle multiple conflicts from the same
machine or domain by appending numbered suffixes.

Renamed GenerateConflictName() to GenerateUniqueConflictNameAsync() which:
- Checks if base conflict name exists using storage.ExistsAsync()
- If exists, tries numbered versions: (source 2), (source 3), etc.
- Supports up to 100 conflicts from the same source
- Falls back to timestamp if 100+ conflicts exist

Examples:
- First conflict: "document (andre-vivobook).txt"
- Second conflict: "document (andre-vivobook 2).txt"
- Third conflict: "document (andre-vivobook 3).txt"

Or for remote:
- First conflict: "document (disk.cx).txt"
- Second conflict: "document (disk.cx 2).txt"

This prevents:
- MoveAsync failures due to existing conflict files
- Data loss from overwriting previous conflict files
- Database inconsistencies

Both RenameLocal and RenameRemote now use this collision-safe method.
The method doesn't access any instance data, so marking it as static
resolves the code analysis warning CA1822.
@Menelion Menelion merged commit 346bb92 into master Nov 5, 2025
1 check passed
@Menelion Menelion deleted the claude/resolve-todo-comment-011CUqUFmmxPGzYxNGWA2t6H branch November 5, 2025 22:58
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