-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Make sure that SettingFile arg is parsed before we load the settings #7449
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
Conversation
… build environment.
aca4308 to
5979c49
Compare
f98c185 to
ebf9239
Compare
ebf9239 to
5c48dbc
Compare
| { | ||
| if (consoleSessionSetting.EnableConsoleSessionConfiguration == true) | ||
| { | ||
| if (!string.IsNullOrEmpty(consoleSessionSetting.ConsoleSessionConfigurationName)) |
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.
We could combine three if in one or use ? operator in just single return.
| if (MatchSwitch(switchKey, "settingsfile", "settings")) | ||
| { | ||
| // parse setting file arg and don't write error as there is no host yet. | ||
| if (!ParseSettingFileHelper(args, ++i, null)) |
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.
Maybe use TryParseSettingFileHelper?
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.
updated
| { | ||
| if (switchKey.Length >= smallestUnambiguousMatch.Length) | ||
| { | ||
| return true; |
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.
We could exclude if-s and use single return.
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.
sorry, I don't follow what you are saying.
Well, looking at the code, I made a guess.
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.
I meant
return (match.Trim().ToLowerInvariant().IndexOf(switchKey, StringComparison.Ordinal) == 0) && (switchKey.Length >= smallestUnambiguousMatch.Length)
| { | ||
| // We need to read the settings file before we create the console host | ||
| string[] tempArgs = new string[args.GetLength(0)]; | ||
| args.CopyTo(tempArgs, 0); |
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.
Could you please clarify why we need clone args?
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.
The existing code cloned the args. I don't want to break something by not cloning.
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.
Reviewing the code. I don't think it has to be. I especially don't think it has to be twice. compromise, I'll remove the second clone, you file an issue to remove the first one.
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.
Done #7457.
| } | ||
|
|
||
| #region Internal properties | ||
| internal bool AbortStartup |
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.
Should #region be in position with the line?
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.
updated
f48196f to
ed941fa
Compare
|
@iSazonov I believe I have addressed all your comments one way or another. |
iSazonov
left a comment
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.
Leave a comment
| /// The command line parameters to be processed. | ||
| /// </param> | ||
| /// <param name="argIndex"> | ||
| /// The index in args to the argument following '-SettingFile'. |
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.
The parameter name is generic but comment says that it is used only for '-SettingFile' - should the parameter name reflects the fact?
| var consoleSessionSetting = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig); | ||
|
|
||
| return (consoleSessionSetting?.EnableConsoleSessionConfiguration == true && !string.IsNullOrEmpty(consoleSessionSetting?.ConsoleSessionConfigurationName)) ? | ||
| consoleSessionSetting.ConsoleSessionConfigurationName : string.Empty; |
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.
Maybe use more short name like settings to get more short code strings.
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 an existing variable name. Please file an issues
| bool noexitSeen = false; | ||
| for (int i = 0; i < args.Length; ++i) | ||
| { | ||
| var switchKeyResults = GetSwitchKey(args, ref i, null, ref noexitSeen); |
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.
It is not clear that we get from the method. I'd replace var with explicit type.
Can we use:
(string switchKey, bool shouldBreak) = GetSwitchKey(args, ref i, null, ref noexitSeen); Named argument for null will be good.
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.
resolved
|
|
||
| string switchKey = switchKeyResults.SwitchKey; | ||
|
|
||
| if (MatchSwitch(switchKey, "settingsfile", "settings")) |
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.
Named arguments will be good for constants. Below I see some such patterns.
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.
resolved
| path = path.Replace(StringLiterals.AlternatePathSeparator, | ||
| StringLiterals.DefaultPathSeparator); | ||
|
|
||
| return Path.GetFullPath(path); |
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.
The method is used once and then we call File.Exist() where Path.GetFullPath() is called again.
https://source.dot.net/#System.IO.FileSystem/System/IO/File.cs,119
We could simplify the TryParseSettingFileHelper() method - remove try-catch there (line 429), move the line 574 to TryParseSettingFileHelper() before File.Exist()
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.
existing code, please file an issue, the method was just changed from an instance to static
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.
Done #7469.
| $testPid = & $powershell -NoLogo -NoProfile -SettingsFile $configFile -Command '$PID' | ||
|
|
||
| Export-PSOsLog -After $after -Verbose | Set-Content -Path $contentFile | ||
| Export-PSOsLog -after $after -LogPid $testPid -Verbose | Set-Content -Path $contentFile |
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.
Please revert -after to -After.
| { | ||
| configFile = NormalizeFilePath(args[argIndex]); | ||
| } | ||
| catch (Exception ex) |
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.
I believe we could remove the try-catch. See my comment for NormalizeFilePath() method.
dantraMSFT
left a comment
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.
None of my comments are blocking but recommend you reconsider adding release logic for the new Dbg.Assert calls.
|
|
||
|
|
||
| class PSLogItem | ||
| { |
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.
I suggest updating the comment block at the top of the file to call out the change in format.
Other than that, this file LGTM
| env: TRAVIS_CI_CACHE_NAME=linux | ||
| - os: osx | ||
| osx_image: xcode8.1 | ||
| osx_image: xcode9.4 |
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.
I assume this means we won't be running tests against the prior OS version, right?
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.
I found no differences in the log format, but yes correct
| /// </param> | ||
| internal static void EarlyParse(string[] args) | ||
| { | ||
| Dbg.Assert(!_dirtyEarlyParse, "This instance has already been used. Create a new instance."); |
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.
The assert message is misleading. The method can only be called once since _dirtyEarlyParse is a static field.
Additionally, back this up with a release test or simply return if true. We don't run debug tests enough to catch this problem.
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.
removed, I verified this can be run multiple times
| /// </param> | ||
| private static void EarlyParseHelper(string[] args) | ||
| { | ||
| Dbg.Assert(args != null, "Argument 'args' to ParseHelper should never be null"); |
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.
Back this up with a check in release mode. At a minimum, silently ignore and return.
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.
resolved
| /// The index in args to the argument to process. | ||
| /// </param> | ||
| /// <param name="parser"> | ||
| /// Used to allow the helper to write errors to the console. If not supplied, Files will not be parsed. |
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.
The comment about writing errors doesn't appear to apply.
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.
Updated comment (I have not pushed at this point.)
| string[] tempArgs = new string[args.GetLength(0)]; | ||
| args.CopyTo(tempArgs, 0); | ||
|
|
||
| CommandLineParameterParser.EarlyParse(tempArgs); |
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.
I've created issue #7460 to move this call to UnmanagedPSEntry.Start prior to PSEtwLog.LogConsoleStartup().
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.
Thanks
| Export-PSOsLog -After $after -Verbose | Set-Content -Path $contentFile | ||
| $items = Get-PSOsLog -Path $contentFile -Id $logId -After $after -TotalCount 3 -Verbose | ||
| # Made tests more reliable | ||
| Start-Sleep -Milliseconds 500 |
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.
I've created issue #7462 to address the Start-Sleep workaround as well as the possible false-positive in filtering test below.
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.
Thanks
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.
I'm pretty sure tuple field names are case sensitive.
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.
updated
2906b02 to
b8dcdfe
Compare
f1aec6f to
00c2a10
Compare
PR Summary
Make sure that SettingFile arg is parsed before we load the settings
Also, fix the following Travis-ci issues:
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests