-
Notifications
You must be signed in to change notification settings - Fork 31
[905583]Fix to catch unauthorized exception when config file is created while setting sdkpath #71
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
Changes from all commits
4dca19a
72a7605
07d101b
1db3fa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,12 +155,12 @@ internal static void DefaultConsoleLogger (TraceLevel level, string message) | |
| } | ||
| } | ||
|
|
||
| public static void SetPreferredAndroidSdkPath (string path, Action<TraceLevel, string> logger = null) | ||
| public static bool SetPreferredAndroidSdkPath (string path, Action<TraceLevel, string> logger = null) | ||
| { | ||
| logger = logger ?? DefaultConsoleLogger; | ||
|
|
||
| var sdk = CreateSdk (logger); | ||
| sdk.SetPreferredAndroidSdkPath (path); | ||
| var sdk = CreateSdk(logger); | ||
| return sdk.SetPreferredAndroidSdkPath(path); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here, no need for the temp var, just |
||
|
|
||
| public static void SetPreferredJavaSdkPath (string path, Action<TraceLevel, string> logger = null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,7 +133,7 @@ protected override string GetShortFormPath (string path) | |
| return path; | ||
| } | ||
|
|
||
| public override void SetPreferredAndroidSdkPath (string path) | ||
| public override bool SetPreferredAndroidSdkPath (string path) | ||
| { | ||
| path = NullIfEmpty (path); | ||
|
|
||
|
|
@@ -145,8 +145,9 @@ public override void SetPreferredAndroidSdkPath (string path) | |
| doc.Root.Add (androidEl); | ||
| } | ||
|
|
||
| androidEl.SetAttributeValue ("path", path); | ||
| SaveConfig (doc); | ||
| androidEl.SetAttributeValue("path", path); | ||
| bool setConfig = SaveConfig(doc, Logger); | ||
| return setConfig; | ||
| } | ||
|
|
||
| public override void SetPreferredJavaSdkPath (string path) | ||
|
|
@@ -162,7 +163,7 @@ public override void SetPreferredJavaSdkPath (string path) | |
| } | ||
|
|
||
| javaEl.SetAttributeValue ("path", path); | ||
| SaveConfig (doc); | ||
| SaveConfig (doc, Logger); | ||
| } | ||
|
|
||
| public override void SetPreferredAndroidNdkPath (string path) | ||
|
|
@@ -178,22 +179,30 @@ public override void SetPreferredAndroidNdkPath (string path) | |
| } | ||
|
|
||
| androidEl.SetAttributeValue ("path", path); | ||
| SaveConfig (doc); | ||
| SaveConfig (doc, Logger); | ||
| } | ||
|
|
||
| void SaveConfig (XDocument doc) | ||
| bool SaveConfig (XDocument doc, Action<TraceLevel, string> logger) | ||
| { | ||
| string cfg = UnixConfigPath; | ||
| List <string> created = null; | ||
|
|
||
| if (!File.Exists (cfg)) { | ||
| string dir = Path.GetDirectoryName (cfg); | ||
| if (!Directory.Exists (dir)) { | ||
| Directory.CreateDirectory (dir); | ||
| AddToList (dir); | ||
| } | ||
| AddToList (cfg); | ||
| } | ||
| try | ||
| { | ||
| Directory.CreateDirectory(dir); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| logger(TraceLevel.Error, $"Unable to create directory {dir}, user do not have the right permissions, {ex.Message}."); | ||
| return false; | ||
| } | ||
| AddToList(dir); | ||
| } | ||
| AddToList (cfg); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file uses tabs, not spaces, for indentation. All the indentation and associated formatting is wrong. |
||
| } | ||
| doc.Save (cfg); | ||
| FixOwnership (created); | ||
|
|
||
|
|
@@ -203,6 +212,7 @@ void AddToList (string path) | |
| created = new List <string> (); | ||
| created.Add (path); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| static readonly string GetUnixConfigDirOverrideName = $"UnixConfigPath directory override! {typeof (AndroidSdkInfo).AssemblyQualifiedName}"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is "public"-ish API, used in numerous places, and it might not be easy to keep all such places synchronized with each other. This should thus be treated as an ABI break and avoided if at all possible.
Additionally, I fail to see why it would be a "bad" thing for
AndroidSdkInfo.SetPreferredAndroidSdkPath()to throw an exception when it can't save the specified value. Why can't the caller catch the exception?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue is caused because user do not have the right permissions to create the
$HOME/.config/xbuild/monodroid-config.xmland it is caused by 4dca19a#diff-c96432cf25d2723c79c03d426742f345L192. The issue is coming from xamarin-android-tools which is a submodule for installer. My fix is to handle this issue properly in android-tools, so that installer can handle it with an error slide and the user knows that installer do not have the right permissions to create $HOME/.config/xbuild/monodroid-config.xml. This is not hiding the error but a way to show user that there is a permission issue and installer cannot continue Xamarin.Android installation.