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 error when removing file from GameRoot #3196

Merged
merged 1 commit into from
Nov 16, 2020

Conversation

HebaruSan
Copy link
Member

Problem

If you install a mod that installs a file to GameRoot (e.g. AdvancedFlyByWire), and then remove it, the removal fails:

About to remove:

 * Advanced Fly-By-Wire (Windows) 1.8.3.2
 * Toolbar Controller 1:0.1.9.4
 * ClickThrough Blocker 1:0.1.10.14
 * Zero MiniAVC 1:1.1.0.1
Removing AdvancedFlyByWire...
/ is already absolute
Error during installation!
If the above message indicates a download error, please try again. Otherwise, please open an issue for us to investigate.
If you suspect a metadata problem: https://github.com/KSP-CKAN/NetKAN/issues/new/choose
If you suspect a bug in the client: https://github.com/KSP-CKAN/CKAN/issues/new/choose

Cause

In #3180 we fixed KSPPathUtils.NormalizePath to no longer incorrectly convert "/" to "", because those are two different directories, and normalization is supposed to generate a standardized format of the same directory.

That change indirectly confused this loop:

// remove the system paths, leaving the path under the instance directory
var relativeHead = KSPPathUtils.ToRelative(dir, gameDir);
var pathArray = relativeHead.Split('/');
var builtPath = string.Empty;
foreach (var path in pathArray)
{
builtPath += path + '/';
results.Add(KSPPathUtils.ToAbsolute(builtPath, gameDir));
}

For a file in GameRoot, the absolute path to the game folder is included in the directories parameter of ModuleInstaller.AddParentDirectories, which results in relativeHead containing the empty string. Then in the first iteration of the loop, buildPath is set to /, and ToAbsolute calls NormalizePath on it, after which it is still /, so ToAbsolute throws because that path is already absolute.

Considered and not done

We could change ToAbsolute to use some method other than NormalizePath to massage its inputs. I think it would be better to continue to uncover places in Core where paths are treated sloppily and fix them. ToAbsolute("/", "/myroot/") should throw an exception if ToAbsolute("/afile", "/myroot/") would.

Changes

Now if relativeHead is empty, that means there are no parent folders to check, so we skip that loop.

Fixes #3195.

@HebaruSan HebaruSan added Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Pull request labels Nov 14, 2020
@DasSkelett
Copy link
Member

Do you think this is worth adding tests for? ModuleInstallerDirTest.cs already has some for AddParentDirectories(). I feel like this is something we could accidentally break again by changing code only related over multiple corners.

@HebaruSan
Copy link
Member Author

Yes, I agree that's a good idea.

@HebaruSan HebaruSan added the In progress We're still working on this label Nov 16, 2020
@HebaruSan HebaruSan removed the In progress We're still working on this label Nov 16, 2020
@HebaruSan
Copy link
Member Author

OK, added a test for that, as well as for Ships/Script since there's already a framework for it.

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.

Great, let's release our users from the install-but-never-uninstall-again trap 😄

@HebaruSan HebaruSan merged commit 416e13b into KSP-CKAN:master Nov 16, 2020
@HebaruSan HebaruSan deleted the fix/gameroot-uninst branch November 16, 2020 23:46
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"/ is already absolute" when trying to uninstall a mod
2 participants