Implement conflict renaming logic#10
Merged
Menelion merged 5 commits intoNov 5, 2025
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.