Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions src/System.Management.Automation/engine/AutomationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,22 @@ internal class AutomationEngine
internal AutomationEngine(PSHost hostInterface, InitialSessionState iss)
{
#if !UNIX
// Update the env variable PathEXT to contain .CPL
var pathext = Environment.GetEnvironmentVariable("PathEXT");
pathext = pathext ?? string.Empty;
bool cplExist = false;
if (pathext != string.Empty)
// Update the env variable PATHEXT to contain .CPL
var pathext = Environment.GetEnvironmentVariable("PATHEXT");

if (string.IsNullOrEmpty(pathext))
{
string[] entries = pathext.Split(Utils.Separators.Semicolon);
foreach (string entry in entries)
{
string ext = entry.Trim();
if (ext.Equals(".CPL", StringComparison.OrdinalIgnoreCase))
{
cplExist = true;
break;
}
}
Environment.SetEnvironmentVariable("PATHEXT", ".CPL");
}

if (!cplExist)
else if (!(pathext.EndsWith(";.CPL", StringComparison.OrdinalIgnoreCase) ||
pathext.StartsWith(".CPL;", StringComparison.OrdinalIgnoreCase) ||
pathext.Contains(";.CPL;", StringComparison.OrdinalIgnoreCase) ||
pathext.Equals(".CPL", StringComparison.OrdinalIgnoreCase)))
{
pathext = (pathext == string.Empty) ? ".CPL" :
pathext.EndsWith(";", StringComparison.OrdinalIgnoreCase)
? (pathext + ".CPL") : (pathext + ";.CPL");
Environment.SetEnvironmentVariable("PathEXT", pathext);
// Fast skip if we already added the extention as ";.CPL".
// Fast skip if user already added the extention.
pathext += pathext[pathext.Length - 1] == ';' ? ".CPL" : ";.CPL";
Environment.SetEnvironmentVariable("PATHEXT", pathext);
}
#endif

Expand All @@ -69,9 +61,7 @@ internal AutomationEngine(PSHost hostInterface, InitialSessionState iss)
CommandDiscovery = new CommandDiscovery(Context);

// Load the iss, resetting everything to it's defaults...
iss.Bind(Context, /*updateOnly*/ false);

InitialSessionState.SetSessionStateDrive(Context, true);
iss.Bind(Context, updateOnly: false, module: null, noClobber: false, local: false, setLocation: true);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2097,12 +2097,7 @@ public virtual HashSet<string> StartupScripts

private object _syncObject = new Object();

internal void Bind(ExecutionContext context, bool updateOnly)
{
Bind(context, updateOnly, null, /*noClobber*/false, /*local*/ false);
}

internal void Bind(ExecutionContext context, bool updateOnly, PSModuleInfo module, bool noClobber, bool local)
internal void Bind(ExecutionContext context, bool updateOnly, PSModuleInfo module, bool noClobber, bool local, bool setLocation)
{
Host = context.EngineHostInterface;
lock (_syncObject)
Expand Down Expand Up @@ -2205,7 +2200,7 @@ internal void Bind(ExecutionContext context, bool updateOnly, PSModuleInfo modul
}
}

SetSessionStateDrive(context, setLocation: false);
SetSessionStateDrive(context, setLocation: setLocation);
}

private void Bind_SetVariables(SessionStateInternal ss)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,7 @@ internal PSModuleInfo LoadModuleManifest(
{
try
{
iss.Bind(Context, /*updateOnly*/ true);
iss.Bind(Context, updateOnly: true, module: null, noClobber: false, local: false, setLocation: false);
}
catch (Exception e)
{
Expand Down Expand Up @@ -6765,7 +6765,7 @@ internal PSModuleInfo LoadBinaryModule(PSModuleInfo parentModule, bool trySnapIn
iss.DisableFormatUpdates = true;

// Load the cmdlets and providers, bound to the new module...
iss.Bind(Context, /*updateOnly*/ true, module, options.NoClobber, options.Local);
iss.Bind(Context, updateOnly: true, module, options.NoClobber, options.Local, setLocation: false);

// Scan all of the types in the assembly to register JobSourceAdapters.
IEnumerable<Type> allTypes = new Type[] { };
Expand Down