Repository navigation
ADFA-5444: Copy templates on install, delete on uninstall, no restore - #2049
jimturner-adfa wants to merge 6 commits into
Conversation
…lates Uninstalling a plugin-provided template (e.g. from the Flutter plugin) unconditionally tried to "restore" it to Downloads, tripping a false "already exists" collision whenever an unrelated file happened to share its name there - even though the template was extracted straight from the plugin's own bundled resources and never touched Downloads in the first place. A plugin-provenance item now just gets deleted from the templates directory on uninstall, matching how PluginProjectManager and IdeTemplateServiceImpl already remove these templates elsewhere. User-imported templates keep the existing restore-to-Downloads behavior, since those genuinely came from there. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
|
Merge-order note: if this merges after #2045 (ADFA-5446), you'll hit one real conflict in Resolution to use when that conflict comes up: /**
* Removes [item] from the templates directory and reloads templates. A plugin-provided item is
* just deleted, since it never came from Downloads in the first place. A user-imported item is
* restored to Downloads first, failing with [TemplateReplaceConflictException] if a file of the
* same name already exists there, unless [overwrite] is true.
*/
suspend fun uninstallTemplate(
item: CgtFileItem,
overwrite: Boolean = false,
): Result<Unit>No other files conflict between the two PRs - confirmed with a full local merge simulation (compiles clean, all 22 tests across both PRs pass together). |
Elissa-AppDevforAll
left a comment
There was a problem hiding this comment.
I could uninstall the individual templates created by the Flutter plugin.
|
There's a logic bug here. It doesn't matter where a template comes from (plugin or cgt file). We don't need a "restore" function for templates. If you want to add a "disable" feature to match the plugins, I could see that. But uninstalling a template doesn't need special undo functionality. The user can re-install the original cgt file. |
…-a-Flutter-template
…-a-Flutter-template
…-manager-Cant-uninstall-a-Flutter-template
Per review: drop the idea of "restore". Install now copies the .cgt from Downloads into the templates directory and leaves the original in place; uninstall just deletes the installed copy, whatever its provenance. A user re-installs from the original .cgt (still in Downloads, where the list shows it again once the installed twin is gone) or by re-installing the plugin that provided it. This removes the restore-to-Downloads path and its "already exists in Downloads" check, which is what made uninstall fail whenever the original was still there. Tests stub ITemplateProvider.getInstance so the success paths run; the copy-on-install and uninstall-with-twin tests fail against the old move/restore code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches the Plugins tab: tapping Install on a Downloads template now opens an "Install Template Collection" dialog with the same "Delete installation file after install" checkbox, unchecked by default. When it is ticked, the Downloads original is deleted only after the install succeeds; a failed delete shows the Plugins tab's "Could not delete the installation file" error and leaves the install in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Per review: remove the idea of restoring an uninstalled template to Downloads, which is what made uninstall fail whenever a same-named file was already there. This replaces the overwrite/Replace-in-Downloads flow with the design from #2049 (Hal's option 1), applied onto current stage: - installTemplate copies the .cgt and leaves the Downloads original; uninstallTemplate deletes the installed copy, whatever its provenance. - Install opens an "Install Template Collection" dialog with the Plugins tab's "Delete installation file after install" checkbox. - Removed: the overwrite parameter, TemplateReplaceConflictException, ShowReplaceConfirmation, ReplaceTemplateInDownloadsDialog and its strings. A user reinstalls from the original .cgt, which the list shows again once the installed copy is gone, or by reinstalling the plugin that provided it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nfirm (#2045) * ADFA-5446: Confirm template uninstall/replace instead of failing silently Uninstalling a template refused to run when a same-named file already sat in Downloads, with no way to proceed - the user's only options were delete the Downloads file themselves or give up. Add an "Uninstall template?" confirmation (mirroring the existing Delete confirmation) and, on a Downloads name collision, a "Replace file in Downloads?" prompt that lets the user overwrite it instead of hitting a dead end. TemplateRepository.uninstallTemplate gains an `overwrite` parameter; a collision without it now returns TemplateReplaceConflictException instead of a generic IllegalStateException, so the ViewModel can route it to the new confirmation dialog rather than a plain error toast. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * ADFA-5446: Restore collision logging and clarify the overwrite-delete-fails message The replace-conflict path returns early via return@withContext, so it never reached the catch blocks' logger.error call the old IllegalStateException path used to hit - a repeated replace conflict left no log trace. Log it directly where it's decided instead. Also: when overwrite=true and the subsequent source delete fails, the old Downloads content has already been irrecoverably replaced, but the thrown message was identical to the non-overwrite rollback case ("failed to delete source file"), which reads as if nothing happened. The message now says the template exists in both places, since that's what's actually true and rolling back would only destroy the new copy too for nothing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * ADFA-5446: Add KDoc to the uninstall-confirmation public declarations CodeRabbit review nitpicks: TemplateRepositoryImpl.uninstallTemplate's rollback-on-delete-failure contract, ShowUninstallConfirmation, and UninstallTemplateConfirmationDialog were undocumented public declarations. Added brief KDoc to each. Not changed: CodeRabbit's suggestion that the test file's single-arg uninstallTemplate calls need an explicit `overwrite = false` because "the override does not inherit the interface default" is incorrect - Kotlin overrides inherit the base declaration's default parameter value at every call site regardless of the reference's static type, and those exact calls already compile and pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * ADFA-5446: Keep the Downloads file safe when an uninstall replace fails Address review findings on #2045: - copyTo(overwrite = true) deletes the target before copying, so a copy that failed partway destroyed the user's Downloads file. Copy into a hidden .part file and rename it into place; a failed copy now leaves the existing file intact and no truncated file behind. - The Replace dialog showed the extension-less display name, which names no real file. It now shows the conflicting file's exact name on disk, carried from TemplateReplaceConflictException. - The conflict check was case-sensitive while the list filter is not, so a Downloads twin differing only in case was hidden and silently duplicated. Match it case-insensitively and replace that file in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ADFA-5446: Replace the Downloads file with Files.move, not renameTo File.renameTo leaves replacing an existing target unspecified, and a confirmed Replace always has one. Files.move with REPLACE_EXISTING makes the replacement part of the documented contract (API 26+; minSdk is 28). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ADFA-5446: Only replace a Downloads file when overwrite was confirmed copyThroughTempFile used Files.move(..., REPLACE_EXISTING) unconditionally, so a file that appeared at the target path without the caller's prior existence check seeing it (a race, or the check itself failing to list the directory) was silently overwritten - exactly the bug class this PR exists to fix, just reached a different way. copyThroughTempFile now takes replaceExisting, true only when the uninstallTemplate caller already found and confirmed the collision. In the unconfirmed case, Files.move without REPLACE_EXISTING throws FileAlreadyExistsException if something is there after all; that's now converted to the same TemplateReplaceConflictException the normal pre-check already raises, so the ViewModel's existing Replace-confirmation handling covers it without any new UI path. Regression test: uninstallTemplate_existingFileInvisibleToTheLookup_ stillFailsWithReplaceConflict_insteadOfOverwriting makes downloadDir unreadable so the pre-move listFiles() lookup misses an existing file there. Against the old code this reaches success and then ITemplateProvider.getInstance(reload = true), which isn't wired up on the unit test classpath (see the class's own KDoc on why a happy-path test isn't included) - so the old code silently treats this as success. It fails with TemplateReplaceConflictException now. Verified: :app:compileV8DebugKotlin, Spotless, and TemplateRepositoryImplTest (19/19) pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * ADFA-5446: Drop restore: install copies, uninstall deletes Per review: remove the idea of restoring an uninstalled template to Downloads, which is what made uninstall fail whenever a same-named file was already there. This replaces the overwrite/Replace-in-Downloads flow with the design from #2049 (Hal's option 1), applied onto current stage: - installTemplate copies the .cgt and leaves the Downloads original; uninstallTemplate deletes the installed copy, whatever its provenance. - Install opens an "Install Template Collection" dialog with the Plugins tab's "Delete installation file after install" checkbox. - Removed: the overwrite parameter, TemplateReplaceConflictException, ShowReplaceConfirmation, ReplaceTemplateInDownloadsDialog and its strings. A user reinstalls from the original .cgt, which the list shows again once the installed copy is gone, or by reinstalling the plugin that provided it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ADFA-5446: Confirm before uninstalling a template Keeps this PR's confirm-before-uninstall step, which the Plugins tab also has, now that nothing is restored: Uninstall opens a dialog and confirmUninstallTemplate does the work, like confirmDeleteDownloadFile. The message says the template is removed and how to get it back (reinstall the .cgt or the plugin), instead of "moves it back to Downloads". The Uninstall and Delete messages now scroll. AlertDialog's text slot does not, so a long file name at 2x font scale was clipped (CodeRabbit). The Install dialog already scrolled. The uninstall-event test fails with the ask-first step reverted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ADFA-5446: Remove a partial copy when installing a template fails installTemplate copies straight to the final path in templatesDir. A copy that failed partway (storage full, say) left a truncated .cgt that never parses, so it was unlisted and could not be uninstalled, and every retry then failed with "already exists". Delete it on IOException, but not on FileAlreadyExistsException: that file belongs to another writer (CodeRabbit). The new test fails without the fix on the "no partial file" assertion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ADFA-5446: Delete only an install destination this install created A failed copy deleted dest even when the failure came before the copy created it. If another writer created dest after the exists() check and the source then failed to open, the cleanup removed that writer's file. Open the source first and create dest with CREATE_NEW (O_EXCL), so the cleanup after a partial copy can only remove a file this call made. The new test fails on the old code: the racing writer's file is deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: yaturner <thursdaynext@gmail.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
ADFA-5444
Removes the idea of "restoring" an uninstalled template, per review (option 1: copy instead of move, and match the Plugins tab).
Changes
installTemplatecopies the.cgtfrom Downloads and leaves the original.uninstallTemplatedeletes the installed copy whatever its provenance. The restore-to-Downloads path and its "already exists in Downloads" check are gone; that check is what made uninstall fail whenever the original was still there (the reported Flutter case).scanTemplatesalready hides a Downloads twin while an installed copy exists). A plugin's template comes back by re-installing the plugin.Review by commit:
2595dd359is the repository change,ff0d1d0c5the UI.123c0ee9dmergesstage.Sites checked
ExternalFileInstallViewModel) already copies into a temp file and never touches the original, so it is unchanged. Plugins opened that way don't delete their original either.TemplateProvenancestays, but only for the card label; it no longer drives uninstall.Testing
TemplateRepositoryImplTest15/15 andTemplateManagerViewModelTest8/8 pass.ITemplateProvideris now stubbed, so the success paths are covered.TemplateRepositoryImpl, exactly the three new behaviour tests fail, each for its named reason: the Downloads original vanished, uninstall was refused with a Downloads twin, and a user template was restored into Downloads.spotlessCheckpasses.ff0d1d0c5), installed in place.plugin_*.cgtstand-in, the filename prefix CoGo uses for provenance.Related
#2045 (ADFA-5446, Replace-in-Downloads on uninstall) only exists to support the restore this PR removes. It should be closed rather than merged.
🤖 Generated with Claude Code