Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uninstallation of manually deleted files and directories #3955

Merged
merged 1 commit into from Dec 14, 2023

Conversation

HebaruSan
Copy link
Member

Problem

  1. Install a mod with CKAN
  2. Delete its files manually (this isn't a good idea, so don't do it normally, but it's how the bug is reproduced, so you have to do it this once)
  3. Uninstall the mod in CKAN
  4. This error is displayed:
    screenshot

Cause

During development to improve the "inconsistencies were found / is registered to but has not been removed" message in #3938, I thought the missing-file case only needed to sneak past File.Delete, which explicitly says it won't throw an exception:

image

However, the underlying exception here is thrown elsewhere:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'c:\program files (x86)\steam\SteamApps\common\Kerbal Space Program\GameData\AJE\RftS\Brown.dds'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.GetAttributes(String path)
   at CKAN.ModuleInstaller.Uninstall(String identifier, HashSet`1& possibleConfigOnlyDirs, Registry registry)

The File.GetAttributes call is and always has been the first thing that happens when deleting files, so that's why this section of code was so aggressive in ignoring exceptions prior to #3938.

Changes

Now if DirectoryNotFoundException or FileNotFoundException are thrown by File.GetAttributes, we log them as debug messages and ignore them. This allows uninstallation to finish for these mods. Exceptions thrown for other reasons, such as permissions or locked files, will still be collected into the error message from #3938.

Fixes #3954.

@HebaruSan HebaruSan added Bug Core (ckan.dll) Issues affecting the core part of CKAN labels Dec 14, 2023
@HebaruSan HebaruSan merged commit 46a97d3 into KSP-CKAN:master Dec 14, 2023
8 checks passed
@HebaruSan HebaruSan deleted the fix/uninstall-manually-deleted branch December 14, 2023 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Core (ckan.dll) Issues affecting the core part of CKAN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: CKAN doesn't delete mods after i delete them manually
1 participant