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

Case insensitive installed file lookup on Windows #3479

Merged
merged 1 commit into from
Nov 17, 2021

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Nov 17, 2021

Problems

Recently, Windows users have been encountering weird install/uninstall errors relating to Scatterer:

screenshot1
screenshot2
screenshot3

Causes

In its latest release, Scatterer renamed its install folder from scatterer to Scatterer (capitalizing the S), but the metadata was unchanged until KSP-CKAN/NetKAN#8862. There was no inflation error because install stanza matching is case insensitive, so find: scatterer matched a path in the ZIP of Scatterer:

{
file = CKANPathUtils.NormalizePath(file);
inst_pattern = new Regex(@"^" + Regex.Escape(file) + @"(/|$)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
else if (find != null)
{
find = CKANPathUtils.NormalizePath(find);
inst_pattern = new Regex(@"(?:^|/)" + Regex.Escape(find) + @"(/|$)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
else if (find_regexp != null)
{
inst_pattern = new Regex(find_regexp,
RegexOptions.IgnoreCase | RegexOptions.Compiled);
}

One user who encountered these errors shared a screenshot confirming that the mod was installed into GameData/scatterer:

GameData

But their registry.json has it as GameData/Scatterer in the installed_files hashes:

https://1drv.ms/u/s!AlCbO5GR6RGwj7RlQn2vSUdicVFNQA?e=pJQfMM

On Windows, filenames are treated as case insensitive, so if we take a filename with mismatched capitalization from the registry and look for it on disk, it will be found. But Dictionary<string, whatever> lookups are case sensitive by default, so if we take a filename with mismatched capitalization from disk and look for it in the registry, it won't be found unless we take extra steps to make that happen.

One place this happens is when we look for manually installed DLLs. This is done by iterating over all the DLLs in GameData and checking whether each one is registered to an installed module. If the capitalization is mismatched, then that code does not find the file and adds it to the list of manually installed DLLs. Later the RelationshipResolver will trip on Scatterer's self-conflict when it sees it in the manually installed DLL list and emit the above strange errors.

Changes

Now on Windows we initialize the installed_file dictionaries with StringComparer.OrdinalIgnoreCase, which makes their key lookup case insensitive. This should allow us to find files properly when going from disk to the registry, so CKAN will no longer think that Scatterer.dll is manually installed.

@HebaruSan HebaruSan added Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Pull request Windows Issues specific for Windows Registry Issues affecting the registry labels Nov 17, 2021
@HebaruSan HebaruSan requested a review from DasSkelett November 17, 2021 20:37
@HebaruSan HebaruSan force-pushed the fix/windows-inst-file-case branch from 581fc10 to 6919fdb Compare November 17, 2021 20:58
Copy link
Member

@DasSkelett DasSkelett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some testing on Windows now, both the metadata changes and this PR solve it on their own, i.e. either updating the metadata or using the updated client are enough to mitigate it, both together obviously works as well.
And I realized that there were more Scatterer releases since the folder name changed, but they have been deleted from SpaceDock. So I'll do some backporting of KSP-CKAN/NetKAN#8862 just to be safe

@HebaruSan HebaruSan merged commit 6d24c67 into KSP-CKAN:master Nov 17, 2021
@HebaruSan HebaruSan deleted the fix/windows-inst-file-case branch November 17, 2021 21:44
@HebaruSan
Copy link
Member Author

both the metadata changes and this PR solve it on their own, i.e. either updating the metadata or using the updated client are enough to mitigate it

Excellent news, that means we don't need to rush the next release. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Registry Issues affecting the registry Windows Issues specific for Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants