Merge pull request #787 from PowerShell/andschwa/platform-module

Remove Microsoft.PowerShell.Platform
This commit is contained in:
Andy Schwartzmeyer committed 2016-04-08 16:07:38 -07:00
commit a6a6ac7c36
35 files changed
+192 -145

No files matched your search

+11 -9
View File
@@ -1,7 +1,5 @@
# Use the .NET Core APIs to determine the current platform; if a runtime
# exception is thrown, we are on FullCLR, not .NET Core.
#
# TODO: import Microsoft.PowerShell.Platform instead
try {
$Runtime = [System.Runtime.InteropServices.RuntimeInformation]
$OSPlatform = [System.Runtime.InteropServices.OSPlatform]
@@ -10,11 +8,15 @@ try {
$IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux)
$IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX)
$IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows)
} catch [System.Management.Automation.RuntimeException] {
$IsCore = $false
$IsLinux = $false
$IsOSX = $false
$IsWindows = $true
} catch {
# If these are already set, then they're read-only and we're done
try {
$IsCore = $false
$IsLinux = $false
$IsOSX = $false
$IsWindows = $true
}
catch { }
}
@@ -122,9 +124,9 @@ function Start-PSBuild {
# FullCLR only builds a library, so there is no runtime component
if ($FullCLR) {
$script:Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, $Executable)
$script:Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, $Executable)
} else {
$script:Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, $Runtime, $Executable)
$script:Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, $Runtime, $Executable)
}
Write-Verbose "script:Output is $script:Output"
@@ -1362,7 +1362,7 @@ namespace Microsoft.PowerShell.Commands
continue;
}
if (Platform.IsWindows() && !Force)
if (Platform.IsWindows && !Force)
{
// Check if the process is owned by current user
if (!IsProcessOwnedByCurrentUser(process))
@@ -2097,7 +2097,7 @@ namespace Microsoft.PowerShell.Commands
}
//LoadUserProfile.
if (Platform.IsWindows())
if (Platform.IsWindows)
{
startInfo.LoadUserProfile = _loaduserprofile;
}
@@ -2193,7 +2193,7 @@ namespace Microsoft.PowerShell.Commands
#endif
//Starts the Process
Process process;
if (Platform.IsWindows())
if (Platform.IsWindows)
{
process = start(startInfo);
}
@@ -2238,7 +2238,7 @@ namespace Microsoft.PowerShell.Commands
{
if (!process.HasExited)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
waithandle = new ManualResetEvent(false);
@@ -117,7 +117,7 @@ namespace Microsoft.PowerShell.Commands
if ( ShouldProcess( dateToUse.ToString() ) )
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
#pragma warning disable 56523
@@ -1,18 +0,0 @@
# Use the .NET Core APIs to determine the current platform; if a runtime
# exception is thrown, we are on FullCLR, not .NET Core.
try {
$Runtime = [System.Runtime.InteropServices.RuntimeInformation]
$OSPlatform = [System.Runtime.InteropServices.OSPlatform]
$IsCore = $true
$IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux)
$IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX)
$IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows)
} catch [System.Management.Automation.RuntimeException] {
$IsCore = $false
$IsLinux = $false
$IsOSX = $false
$IsWindows = $true
}
Export-ModuleMember -Variable IsCore, IsLinux, IsOSX, IsWindows
@@ -1,5 +1,3 @@
function prompt {
"PS " + $(get-location) + "> "
}
Import-Module Microsoft.PowerShell.Platform
@@ -828,7 +828,7 @@ namespace System.Management.Automation
// Porting note: if not otherwise defined, map Windows environment
// variables to their corresponding Linux counterparts
if (Platform.IsLinux() && String.IsNullOrEmpty(value))
if (!Platform.IsWindows && String.IsNullOrEmpty(value))
{
switch (variable)
{
@@ -1023,7 +1023,7 @@ namespace System.Management.Automation
{
get
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
return WinGetUserDomainName();
}
@@ -1059,7 +1059,7 @@ namespace System.Management.Automation
{
get
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
return WinGetUserName();
}
@@ -1088,7 +1088,7 @@ namespace System.Management.Automation
{
get
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
return WinGetMachineName();
}
@@ -1108,7 +1108,7 @@ namespace System.Management.Automation
{
if (m_os == null)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
m_os = WinOSVersion;
}
@@ -1179,7 +1179,7 @@ namespace System.Management.Automation
/// </returns>
private static string InternalGetFolderPath(SpecialFolder folder)
{
if (!Platform.IsWindows())
if (!Platform.IsWindows)
{
return Platform.NonWindowsGetFolderPath(folder);
}
@@ -30,39 +30,54 @@ namespace System.Management.Automation
/// </summary>
internal static class Platform
{
// this queries specifically for Linux or OS X because they are very similar
internal static bool IsLinux()
// Platform variables used to defined corresponding PowerShell built-in variables
public static bool IsLinux
{
#if CORECLR
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|| RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#else
// FullCLR doesn't have a Linux version
return false;
#endif
get
{
#if CORECLR
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
#else
return false;
#endif
}
}
// this is specifically to query for Windows, everything else is considered to be non-Windows
internal static bool IsWindows()
public static bool IsOSX
{
#if CORECLR
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
// FullCLR has only Windows version
return true;
#endif
get
{
#if CORECLR
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#else
return false;
#endif
}
}
// true if cross-platform (always for this project)
internal static bool IsX()
public static bool IsWindows
{
#if CORECLR
// CoreCLR version is cross-platform
return true;
#else
// FullCLR is not cross-platform
return false;
#endif
get
{
#if CORECLR
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
return true;
#endif
}
}
public static bool IsCore
{
get
{
#if CORECLR
return true;
#else
return false;
#endif
}
}
// format files
@@ -89,43 +104,43 @@ namespace System.Management.Automation
internal static bool HasCom()
{
// TODO: catch exception from Type.IsComObject
return IsWindows();
return IsWindows;
}
// The Antimalware Scan Interface is not supported on Linux
internal static bool HasAmsi()
{
return IsWindows();
return IsWindows;
}
internal static bool UsesCodeSignedAssemblies()
{
return !Platform.IsX();
return !Platform.IsCore;
}
// This is mainly with respect to the auto-mounting of
// disconnected network drives on Windows
internal static bool HasDriveAutoMounting()
{
return IsWindows();
return IsWindows;
}
// Linux does not have a registry
internal static bool HasRegistrySupport()
{
return IsWindows();
return IsWindows;
}
// Linux does not have PowerShell execution policies
internal static bool HasExecutionPolicy()
{
return IsWindows();
return IsWindows;
}
// Linux has a single rooted file system
internal static bool HasSingleRootFilesystem()
{
return !IsWindows();
return !IsWindows;
}
// Linux has no notion of file shares. It has mount points
@@ -140,7 +155,7 @@ namespace System.Management.Automation
// the UNC equivalent of a "network drive" aka mount would be the mount itself
internal static bool HasUNCSupport()
{
return IsWindows();
return IsWindows;
}
// Linux uses .net to query file attributes
@@ -152,25 +167,25 @@ namespace System.Management.Automation
// Linux does not have group policy support
internal static bool HasGroupPolicySupport()
{
return IsWindows();
return IsWindows;
}
// non-windows does not have network drive support
internal static bool HasNetworkDriveSupport()
{
return IsWindows();
return IsWindows;
}
// non-windows does not have reparse points
internal static bool SupportsReparsePoints()
{
return IsWindows();
return IsWindows;
}
// non-windows does not support removing drives
internal static bool SupportsRemoveDrive()
{
return IsWindows();
return IsWindows;
}
// Platform methods prefixed NonWindows are:
@@ -190,7 +205,7 @@ namespace System.Management.Automation
internal static bool NonWindowsIsHardLink(FileSystemInfo fileInfo)
{
if (IsLinux())
if (!IsWindows)
{
return LinuxPlatform.IsHardLink(fileInfo);
}
@@ -200,7 +215,7 @@ namespace System.Management.Automation
internal static bool NonWindowsIsSymLink(FileSystemInfo fileInfo)
{
if (IsLinux())
if (!IsWindows)
{
return LinuxPlatform.IsSymLink(fileInfo);
}
@@ -216,7 +231,7 @@ namespace System.Management.Automation
internal static string NonWindowsInternalGetTarget(string path)
{
if (IsLinux())
if (!IsWindows)
{
return LinuxPlatform.FollowSymLink(path);
}
@@ -229,7 +244,7 @@ namespace System.Management.Automation
#if CORECLR
internal static string NonWindowsGetFolderPath(SpecialFolder folder)
{
if (IsLinux())
if (!IsWindows)
{
return LinuxPlatform.GetFolderPath(folder);
}
@@ -242,7 +257,7 @@ namespace System.Management.Automation
internal static string NonWindowsInternalGetLinkType(FileSystemInfo fileInfo)
{
if (IsLinux())
if (!IsWindows)
{
if (NonWindowsIsSymLink(fileInfo))
{
@@ -263,7 +278,7 @@ namespace System.Management.Automation
internal static bool NonWindowsCreateSymbolicLink(string path, string strTargetPath, bool isDirectory)
{
if (IsLinux())
if (!IsWindows)
{
// Linux doesn't care if target is a directory or not
return LinuxPlatform.CreateSymbolicLink(path, strTargetPath);
@@ -276,7 +291,7 @@ namespace System.Management.Automation
internal static bool NonWindowsCreateHardLink(string path, string strTargetPath)
{
if (IsLinux())
if (!IsWindows)
{
return LinuxPlatform.CreateHardLink(path, strTargetPath);
}
@@ -288,7 +303,7 @@ namespace System.Management.Automation
internal static void NonWindowsSetDate(DateTime dateToUse)
{
if (IsLinux())
if (!IsWindows)
{
LinuxPlatform.SetDateInfoInternal date = new LinuxPlatform.SetDateInfoInternal(dateToUse);
LinuxPlatform.SetDate(date);
@@ -301,7 +316,7 @@ namespace System.Management.Automation
internal static string NonWindowsGetDomainName()
{
if (IsLinux())
if (!IsWindows)
{
string fullyQualifiedName = LinuxPlatform.Native.GetFullyQualifiedName();
if (string.IsNullOrEmpty(fullyQualifiedName))
@@ -326,7 +341,7 @@ namespace System.Management.Automation
internal static string NonWindowsGetUserName()
{
if (IsLinux())
if (!IsWindows)
{
return LinuxPlatform.UserName;
}
@@ -338,7 +353,7 @@ namespace System.Management.Automation
internal static string NonWindowsGetMachineName()
{
if (IsLinux())
if (!IsWindows)
{
return LinuxPlatform.HostName;
}
@@ -351,7 +366,7 @@ namespace System.Management.Automation
// Hostname in this context seems to be the FQDN
internal static string NonWindowsGetHostName()
{
if (IsLinux())
if (!IsWindows)
{
string hostName = LinuxPlatform.Native.GetFullyQualifiedName();
if (string.IsNullOrEmpty(hostName))
@@ -370,7 +385,7 @@ namespace System.Management.Automation
internal static bool NonWindowsIsExecutable(string path)
{
if (IsLinux())
if (!IsWindows)
{
return LinuxPlatform.IsExecutable(path);
}
@@ -1810,7 +1810,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
// optional pre-load and binding verification
// Porting Note: DLL.resources are not currently available on Linux
if (!Platform.IsX() && this.VerifyStringResources)
if (!Platform.IsCore && this.VerifyStringResources)
{
DisplayResourceManagerCache.LoadingResult result;
DisplayResourceManagerCache.AssemblyBindingStatus bindingStatus;
@@ -1323,7 +1323,7 @@ namespace System.Management.Automation
// Close the progress pane that may have popped up from analyzing UNC paths.
// Porting note: we don't like this message
if (!Platform.IsX() && context.CurrentCommandProcessor != null)
if (!Platform.IsCore && context.CurrentCommandProcessor != null)
{
ProgressRecord analysisProgress = new ProgressRecord(0, Modules.ScriptAnalysisPreparing, " ");
analysisProgress.RecordType = ProgressRecordType.Completed;
@@ -56,7 +56,7 @@ namespace System.Management.Automation
// turn the command name into a pattern and then match against extensions in PATHEXT.
// The old code would enumerate the file system many more times, once per possible extension.
// Porting note: this is wrong on Linux, where we don't depend on extensions
if (Platform.IsWindows())
if (Platform.IsWindows)
{
commandName = commandName + ".*";
}
@@ -478,7 +478,7 @@ namespace System.Management.Automation
for (int i = 0; i < baseNames.Length; i++)
{
if (name.Equals(baseNames[i], StringComparison.OrdinalIgnoreCase)
|| (!Platform.IsWindows() && Platform.NonWindowsIsExecutable(name)))
|| (!Platform.IsWindows && Platform.NonWindowsIsExecutable(name)))
{
if (result == null)
result = new Collection<string>();
@@ -505,7 +505,7 @@ namespace System.Management.Automation
foreach (var fileName in fileNames)
{
if (fileName.EndsWith(allowedExt, StringComparison.OrdinalIgnoreCase)
|| (!Platform.IsWindows() && Platform.NonWindowsIsExecutable(fileName)))
|| (!Platform.IsWindows && Platform.NonWindowsIsExecutable(fileName)))
{
if (result == null)
result = new Collection<string>();
@@ -499,7 +499,7 @@ namespace System.Management.Automation
// TODO:PSL
// this is probably not right here
if (implementingType == typeof(Microsoft.PowerShell.Commands.FileSystemProvider) && !Platform.IsWindows())
if (implementingType == typeof(Microsoft.PowerShell.Commands.FileSystemProvider) && !Platform.IsWindows)
{
volumeSeparatedByColon = false;
}
@@ -38,7 +38,7 @@ namespace System.Management.Automation
this.TimeGenerated = DateTime.Now;
this.Tags = new List<string>();
if (Platform.IsWindows())
if (Platform.IsWindows)
{
this.User = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
}
@@ -4724,7 +4724,7 @@ End
/// </summary>
internal static string GetClearHostFunctionText()
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
return @"
$RawUI = $Host.UI.RawUI
@@ -5101,6 +5101,32 @@ end
RemotingErrorIdStrings.PSSessionAppName,
ScopedItemOptions.None),
// End: Variables which control remoting behavior
#region Platform
new SessionStateVariableEntry(
SpecialVariables.IsLinux,
Platform.IsLinux,
String.Empty,
ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateVariableEntry(
SpecialVariables.IsOSX,
Platform.IsOSX,
String.Empty,
ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateVariableEntry(
SpecialVariables.IsWindows,
Platform.IsWindows,
String.Empty,
ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateVariableEntry(
SpecialVariables.IsCore,
Platform.IsCore,
String.Empty,
ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
#endregion
};
/// <summary>
@@ -5662,7 +5688,7 @@ if($paths) {
// Porting note: the snapins still require 'ProcessorArchitecture=MSIL' in
// the strong name, which is not in the strong name of assemblies created
// by dotnet-cli
if (!Platform.IsX() &&
if (!Platform.IsCore &&
!string.Equals(assemblyName.FullName, psSnapInInfo.AssemblyName, StringComparison.OrdinalIgnoreCase))
{
string message = StringUtil.Format(ConsoleInfoErrorStrings.PSSnapInAssemblyNameMismatch, psSnapInInfo.AbsoluteModulePath, psSnapInInfo.AssemblyName);
@@ -582,7 +582,7 @@ namespace System.Management.Automation
// module using ""System32" in the key.
// Porting note: psHome cannot be lower-cased on case sensitive file systems
if (Platform.IsWindows())
if (Platform.IsWindows)
{
psHome = psHome.ToLowerInvariant().Replace("\\syswow64\\", "\\system32\\");
}
@@ -600,7 +600,7 @@ namespace System.Management.Automation
/// <returns></returns>
internal static string GetDscModulePath()
{
if (!Platform.IsWindows())
if (!Platform.IsWindows)
{
return string.Empty;
}
@@ -763,7 +763,7 @@ namespace System.Management.Automation
// Porting note: Open PowerShell has a Modules folder in the the application base path which contains the built-in modules
// It must be in the front of the path no matter what.
if (Platform.IsX())
if (Platform.IsCore)
{
currentProcessModulePath = AddToPath(currentProcessModulePath, GetSystemwideModulePath(), 0);
}
@@ -131,7 +131,7 @@ namespace System.Management.Automation
{
var rawArgs = arguments.ToString();
if (tracer.IsEnabled && Platform.IsWindows())
if (tracer.IsEnabled && Platform.IsWindows)
{
// This tracing really shouldn't be in the property getter...
tracer.WriteLine("Raw argument string: {0}", rawArgs);
@@ -1026,8 +1026,8 @@ namespace System.Management.Automation
// On Windows, check the extension list and see if we should try to execute this directly.
// Otherwise, use the platform library to check executability
if ((Platform.IsWindows() && ValidateExtension(this.Path))
|| (!Platform.IsWindows() && Platform.NonWindowsIsExecutable(this.Path)))
if ((Platform.IsWindows && ValidateExtension(this.Path))
|| (!Platform.IsWindows && Platform.NonWindowsIsExecutable(this.Path)))
{
startInfo.UseShellExecute = false;
if (redirectInput)
@@ -90,7 +90,7 @@ namespace System.Management.Automation
// TODO:PSL this is a workaround since the exception below
// hides the internal issue of what's going on in terms of
// execution policy.
if (Platform.IsX())
if (Platform.IsCore)
{
return;
}
@@ -156,6 +156,20 @@ namespace System.Management.Automation
internal const string PSModuleAutoLoading = "PSModuleAutoLoadingPreference";
internal static VariablePath PSModuleAutoLoadingPreferenceVarPath = new VariablePath("global:" + PSModuleAutoLoading);
#region Platform Variables
internal const string IsLinux = "IsLinux";
internal static VariablePath IsLinuxPath = new VariablePath("IsLinux");
internal const string IsOSX = "IsOSX";
internal static VariablePath IsOSXPath = new VariablePath("IsOSX");
internal const string IsWindows = "IsWindows";
internal static VariablePath IsWindowsPath = new VariablePath("IsWindows");
internal const string IsCore = "IsCore";
internal static VariablePath IsCorePath = new VariablePath("IsCore");
#endregion
#region Preference Variables
internal const string DebugPreference = "DebugPreference";
@@ -240,7 +240,7 @@ namespace System.Management.Automation
/// </exception>
internal static string GetApplicationBase(string shellId)
{
if (!Platform.IsX())
if (!Platform.IsCore)
{
// try to get the path from the registry first
string result = GetApplicationBaseFromRegistry(shellId);
@@ -305,7 +305,7 @@ namespace System.Management.Automation
// And built-in modules
string progFileDir;
if (Platform.IsX())
if (Platform.IsCore)
{
progFileDir = Path.Combine(appBase, "Modules");
}
@@ -607,7 +607,7 @@ namespace System.Management.Automation
/// Profile uses this to control profile loading.
/// </remarks>
internal static string ProductNameForDirectory =
Platform.IsWindows() ? "WindowsPowerShell" : Platform.ProductNameForDirectory;
Platform.IsWindows ? "WindowsPowerShell" : Platform.ProductNameForDirectory;
/// <summary>
/// The name of the subdirectory that contains packages.
@@ -964,7 +964,7 @@ namespace System.Management.Automation
// SecurityPrincipal API of .net for now assume Linux
// users have no concept of "Administrator" for now and
// specifically do not map to a check for root user
if (Platform.IsWindows())
if (Platform.IsWindows)
{
System.Security.Principal.WindowsIdentity currentIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(currentIdentity);
@@ -534,7 +534,7 @@ namespace System.Management.Automation.Remoting
// All PowerShell instances will start with the named pipe
// and listner created and running.
if (Platform.IsWindows())
if (Platform.IsWindows)
{
IPCNamedPipeServerEnabled = true;
}
@@ -283,7 +283,7 @@ namespace System.Management.Automation.Remoting
// to verify here.
WSManPluginServerTransportManager serverTransportMgr;
if (Platform.IsWindows())
if (Platform.IsWindows)
{
serverTransportMgr = new WSManPluginServerTransportManager(BaseTransportManager.DefaultFragmentSize, new PSRemotingCryptoHelperServer());
}
@@ -390,7 +390,7 @@ namespace System.Management.Automation.Remoting
// Wrap the provided handle so it can be passed to the registration function
EventWaitHandle eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
if (Platform.IsWindows())
if (Platform.IsWindows)
{
SafeWaitHandle safeWaitHandle = new SafeWaitHandle(requestDetails.shutdownNotificationHandle, false); // Owned by WinRM
ClrFacade.SetSafeWaitHandle(eventWaitHandle, safeWaitHandle);
@@ -326,7 +326,7 @@ namespace System.Management.Automation.Remoting
this.shutdownPluginGCHandle = GCHandle.Alloc(shutdownPlugin);
unmanagedStruct.wsManPluginShutdownPluginCallbackNative = Marshal.GetFunctionPointerForDelegate(shutdownPlugin);
}
if(!Platform.IsWindows())
if(!Platform.IsWindows)
{
WSMPluginOperationShutdownDelegate pluginShutDownDelegate = new WSMPluginOperationShutdownDelegate(WSManPluginManagedEntryWrapper.WSManPSShutdown);
this.WSMPluginOperationShutdownGCHandle = GCHandle.Alloc(pluginShutDownDelegate);
@@ -351,7 +351,7 @@ namespace System.Management.Automation.Remoting
this.pluginSignalGCHandle.Free();
this.pluginConnectGCHandle.Free();
this.shutdownPluginGCHandle.Free();
if(!Platform.IsWindows())
if(!Platform.IsWindows)
{
this.WSMPluginOperationShutdownGCHandle.Free();
}
@@ -265,7 +265,7 @@ namespace System.Management.Automation.Remoting
//RACE TO BE FIXED - As soon as this API is called, WinRM service will send CommandResponse back and Signal is expected anytime
// If Signal comes and executes before registering the notification handle, cleanup will be messed
result = WSManNativeApi.WSManPluginReportContext(creationRequestDetails.unmanagedHandle, 0, creationRequestDetails.unmanagedHandle);
if (Platform.IsWindows() && (WSManPluginConstants.ExitCodeSuccess == result))
if (Platform.IsWindows && (WSManPluginConstants.ExitCodeSuccess == result))
{
registeredShutdownNotification = 1;
@@ -332,7 +332,7 @@ namespace System.Management.Automation.Remoting
isRequestPending = true;
this.requestDetails = requestDetails;
if (Platform.IsWindows())
if (Platform.IsWindows)
{
// Wrap the provided handle so it can be passed to the registration function
SafeWaitHandle safeWaitHandle = new SafeWaitHandle(requestDetails.shutdownNotificationHandle, false); // Owned by WinRM
@@ -336,7 +336,7 @@ namespace System.Management.Automation
// Flow the impersonation policy to pipeline execution thread
// only if the current thread is impersonated (Delegation is
// also a kind of impersonation).
if (Platform.IsWindows())
if (Platform.IsWindows)
{
WindowsIdentity currentThreadIdentity = WindowsIdentity.GetCurrent();
switch (currentThreadIdentity.ImpersonationLevel)
@@ -170,7 +170,7 @@ namespace System.Management.Automation.Remoting
_senderInfo = senderInfo;
_configProviderId = configurationProviderId;
_initParameters = initializationParameters;
if (Platform.IsWindows())
if (Platform.IsWindows)
{
_cryptoHelper = (PSRemotingCryptoHelperServer)transportManager.CryptoHelper;
_cryptoHelper.Session = this;
@@ -1195,7 +1195,7 @@ namespace Microsoft.PowerShell.Commands
// Porting note: only UTF-8 is supported on Linux, which is not an SBCS
if ((_currentEncoding.Equals(_oemEncoding) ||
_currentEncoding.Equals(_defaultAnsiEncoding))
&& !Platform.IsLinux())
&& Platform.IsWindows)
{
NativeMethods.CPINFO cpInfo;
if (NativeMethods.GetCPInfo((uint)_currentEncoding.CodePage, out cpInfo) &&
@@ -490,7 +490,7 @@ namespace Microsoft.PowerShell.Commands
private void MapNetworkDrive(PSDriveInfo drive)
{
// Porting note: mapped network drives are only supported on Windows
if (Platform.IsWindows())
if (Platform.IsWindows)
{
WinMapNetworkDrive(drive);
}
@@ -992,7 +992,7 @@ namespace Microsoft.PowerShell.Commands
// Porting notes: on the non-Windows platforms, the drive never
// uses : as a separator between drive and path
if (!Platform.IsWindows())
if (!Platform.IsWindows)
{
newPSDriveInfo.VolumeSeparatedByColon = false;
}
@@ -1505,7 +1505,7 @@ namespace Microsoft.PowerShell.Commands
{
DirectoryInfo directory = new DirectoryInfo(path);
if (!Platform.IsWindows() && Platform.NonWindowsIsSymLink(directory))
if (!Platform.IsWindows && Platform.NonWindowsIsSymLink(directory))
{
// For Linux, treat symlink to directories like a file
WriteItemObject(directory, path, false);
@@ -2210,7 +2210,7 @@ namespace Microsoft.PowerShell.Commands
if(itemType == ItemType.SymbolicLink)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
success = WinCreateSymbolicLink(path,strTargetPath,isDirectory);
}
@@ -2221,7 +2221,7 @@ namespace Microsoft.PowerShell.Commands
}
else if(itemType == ItemType.HardLink)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
success = WinCreateHardLink(path,strTargetPath);
}
@@ -7981,7 +7981,7 @@ namespace Microsoft.PowerShell.Commands
if (fileSysInfo != null)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
using (SafeFileHandle handle = OpenReparsePoint(fileSysInfo.FullName, FileDesiredAccess.GenericRead))
{
@@ -8018,7 +8018,7 @@ namespace Microsoft.PowerShell.Commands
private static List<string> InternalGetTarget(string filePath)
{
var links = new List<string>();
if (!Platform.IsWindows())
if (!Platform.IsWindows)
{
string link = Platform.NonWindowsInternalGetTarget(filePath);
if (!String.IsNullOrEmpty(link))
@@ -8092,7 +8092,7 @@ namespace Microsoft.PowerShell.Commands
private static string InternalGetLinkType(FileSystemInfo fileInfo)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
return WinInternalGetLinkType(fileInfo.FullName);
}
@@ -8105,7 +8105,7 @@ namespace Microsoft.PowerShell.Commands
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods")]
private static string WinInternalGetLinkType(string filePath)
{
if (Platform.IsLinux())
if (!Platform.IsWindows)
{
throw new Platform.PlatformNotSupportedException();
}
@@ -8169,7 +8169,7 @@ namespace Microsoft.PowerShell.Commands
internal static bool IsHardLink(FileSystemInfo fileInfo)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
return WinIsHardLink(fileInfo);
else
return Platform.NonWindowsIsHardLink(fileInfo);
@@ -8177,7 +8177,7 @@ namespace Microsoft.PowerShell.Commands
internal static bool IsReparsePoint(FileSystemInfo fileInfo)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
// Note that this class also has a enum called FileAttributes, so use fully qualified name
return (fileInfo.Attributes & System.IO.FileAttributes.ReparsePoint)
@@ -8228,7 +8228,7 @@ namespace Microsoft.PowerShell.Commands
internal static bool IsHardLink(ref IntPtr handle)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
return WinIsHardLink(ref handle);
else
return Platform.NonWindowsIsHardLink(ref handle);
@@ -8256,7 +8256,7 @@ namespace Microsoft.PowerShell.Commands
private static string InternalGetTarget(SafeFileHandle handle)
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
return WinInternalGetTarget(handle);
}
@@ -8336,7 +8336,7 @@ namespace Microsoft.PowerShell.Commands
{
// this is a purely Windows specific feature, no feature flag
// used for that reason
if (Platform.IsWindows())
if (Platform.IsWindows)
{
return WinCreateJunction(path,target);
}
@@ -8420,7 +8420,7 @@ namespace Microsoft.PowerShell.Commands
if (!String.IsNullOrEmpty(junctionPath))
{
if (!Platform.IsWindows())
if (!Platform.IsWindows)
{
// For non-Windows platform, treat it as a file. Just delete it.
try
@@ -433,7 +433,7 @@ namespace System.Management.Automation
// There is no signature support on non-Windows platforms (yet), when
// execution reaches here, we are sure the file is under product folder
if (Platform.IsX())
if (Platform.IsCore)
{
return true;
}
@@ -586,7 +586,7 @@ namespace System.Management.Automation
internal static string GetHostName()
{
// Note: non-windows CoreCLR does not support System.Net yet
if (Platform.IsWindows())
if (Platform.IsWindows)
{
return WinGetHostName();
}
@@ -612,7 +612,7 @@ namespace System.Management.Automation
internal static uint GetNativeThreadId()
{
if (Platform.IsWindows())
if (Platform.IsWindows)
{
return WinGetNativeThreadId();
}
+13 -1
View File
@@ -12,7 +12,19 @@ namespace PSTests
[Fact]
public static void TestIsLinux()
{
Assert.True(Platform.IsLinux());
Assert.True(Platform.IsLinux);
}
[Fact]
public static void TestIsWindows()
{
Assert.False(Platform.IsWindows);
}
[Fact]
public static void TestIsCore()
{
Assert.True(Platform.IsCore);
}
[Fact]
+2 -2
View File
@@ -1,5 +1,5 @@
Describe "Import-Module" {
$moduleName = "Microsoft.PowerShell.Platform"
$moduleName = "Microsoft.PowerShell.Security"
BeforeEach {
Remove-Module -Name $moduleName -Force
@@ -21,4 +21,4 @@
{ Import-Module -ModuleInfo $a } | Should Not Throw
(Get-Module -Name $moduleName).Name | Should Be $moduleName
}
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
Describe "Remove-Module" {
$moduleName = "Microsoft.PowerShell.Platform"
$moduleName = "Microsoft.PowerShell.Security"
BeforeEach {
Import-Module -Name $moduleName -Force
-2
View File
@@ -87,8 +87,6 @@ Describe "Select-String" {
}
Context "Filesytem actions" {
$isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)
$testDirectory = $TestDrive
$testInputFile = Join-Path -Path $testDirectory -ChildPath testfile1.txt