Clean up url handler registration #2366
Merged
+47
−36
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.
Background
When it starts up, the CKAN GUI adds support for
ckan://identifier
URLs on Windows and Linux.On Windows, it does this by adding this registry key:
CKAN might need to escalate privileges to make these changes. It detects this after the fact by catching an
UnauthorizedAccessException
when it attempts to set the registry key. If this exception is thrown, ckan.exe re-launches itself as administrator with theregisterUrl
command line flag, which prompts the user whether to allow the increased privileges and then sets the registry key.Problem
The user might see this error when launching CKAN:
If this is fixed, other errors can appear:
Causes
The
DeleteSubKeyTree
call doesn't throwUnauthorizedAccessException
when it can't do its job as we would hope. So this call should have its exceptions caught and ignored just like the lines above it.But if
UnauthorizedAccessException
is thrown, it's re-thrown after it is caught and handled:CKAN/GUI/URLHandlers.cs
Lines 51 to 67 in 9ee3584
This is redundant, because no other code is going to be able to do anything more to help the situation than has already been done, and if the privilege-escalated sub-process is able to set the key, then the user has no reason to care about this exception.
Changes
Now
DeleteSubKeyTree
is called within thetry
block above its current location, and we don't re-throw anyUnauthorizedAccessException
s. This prevents the error message from bothering the user.Fixes #2362.