Add rename option for file collisions during archive#19
Open
ggfevans wants to merge 5 commits intomfarr:mainfrom
Open
Add rename option for file collisions during archive#19ggfevans wants to merge 5 commits intomfarr:mainfrom
ggfevans wants to merge 5 commits intomfarr:mainfrom
Conversation
- Extend SimpleArchiverPromptModal to support optional third button - Add generateUniqueArchivePath helper for timestamp-based naming - Update archiveFile to show Replace/Rename/Cancel for collisions - Generate unique filenames using YYYYMMDD-HHMMSS format - Handle edge cases: files without extensions, multiple renames per second - Preserve both existing and new files when rename is chosen - Maintain backward compatibility with two-button modal usage Fixes mfarr#18
Resolves issue where unarchiving files from folders with leading zeros (e.g., 00-inbox) incorrectly stripped the leading zero, causing files to be restored to wrong locations (e.g., 0-inbox). Root cause: Unarchive operation was not normalizing paths before passing them to Obsidian's file management APIs, unlike the archive operation which consistently normalized all paths. Changes: - Added normalizePath() to folder creation in moveFileOutOfArchive() - Added normalizePath() to file rename in moveFileOutOfArchive() This ensures consistent path handling between archive and unarchive operations, preventing leading zeros from being stripped. Fixes mfarr#15 Tested scenarios: - Single leading zero (00-inbox, 01-projects) - Multiple leading zeros (000-archive) - Single zero folders (0-temp) - Deeply nested numeric folders - Regular folders (regression test)
- Add smart merge when archiving folders with existing destination - Compare file contents before replacing (byte-level comparison) - Skip identical files, replace only when content differs - Track merge statistics (added, replaced, skipped, failed) - Handle errors gracefully without stopping entire merge - Only delete source folder when completely empty Fixes mfarr#5
- Integrate folder merge functionality from main branch - Combine rename option (files) with merge option (folders) - Folders show Merge/Cancel prompt (2-button) - Files show Replace/Rename/Cancel prompt (3-button) - Fix success message to capture original filename before rename - Both features now work together seamlessly
- Move originalName declaration outside try-catch for proper scope - Ensure both success and error messages reference original filename - Prevents confusion if file.name is mutated during error handling
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.
Fixes #18
Summary
Adds a rename option when archiving a file that already exists in the archive destination, allowing users to preserve both versions.
Changes
SimpleArchiverPromptModalto support optional third buttongenerateUniqueArchivePathhelper method for timestamp-based unique namesYYYYMMDD-HHMMSSformatUser Experience
When archiving a file that already exists in the archive, users now see three options:
Example: Archiving
note.mdwhen it already exists generatesnote-20251014-232547.mdDesign Decisions
We considered prompting the user with Obsidian's native rename dialog to let them specify a custom name. However, we chose automatic timestamp-based naming for several reasons:
The timestamp format (
YYYYMMDD-HHMMSS) is human-readable, sortable, and handles edge cases like multiple renames in the same second by appending a counter.Implementation Details
middleButtonTextandmiddleCallbackparametersCompatibility
Testing
Tested with:
All scenarios handled correctly with proper unique name generation and user feedback.