mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Cleanup unused pinvokes on unix (#9531)
* Remove TemporaryDirectory() * Remove GetUserName() * Use Environment.UserName on Unix * Remove old comment * Use Environment.UserName on Windows too
This commit is contained in:
@@ -573,40 +573,6 @@ namespace System.Management.Automation
|
||||
return (ErrorCategory)Unix.NativeMethods.GetErrorCategory(errno);
|
||||
}
|
||||
|
||||
private static string s_userName;
|
||||
public static string UserName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(s_userName))
|
||||
{
|
||||
s_userName = NativeMethods.GetUserName();
|
||||
}
|
||||
|
||||
return s_userName ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static string TemporaryDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
// POSIX temporary directory environment variables
|
||||
string[] environmentVariables = { "TMPDIR", "TMP", "TEMP", "TEMPDIR" };
|
||||
string dir = string.Empty;
|
||||
foreach (string s in environmentVariables)
|
||||
{
|
||||
dir = System.Environment.GetEnvironmentVariable(s);
|
||||
if (!string.IsNullOrEmpty(dir))
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
|
||||
return "/tmp";
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsHardLink(ref IntPtr handle)
|
||||
{
|
||||
// TODO:PSL implement using fstat to query inode refcount to see if it is a hard link
|
||||
@@ -669,10 +635,6 @@ namespace System.Management.Automation
|
||||
[DllImport(psLib, CharSet = CharSet.Ansi)]
|
||||
internal static extern int GetErrorCategory(int errno);
|
||||
|
||||
[DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.LPStr)]
|
||||
internal static extern string GetUserName();
|
||||
|
||||
[DllImport(psLib)]
|
||||
internal static extern int GetPPid(int pid);
|
||||
|
||||
|
||||
@@ -101,9 +101,9 @@ namespace System.Management.Automation
|
||||
{
|
||||
// domain\user on Windows, just user on Unix
|
||||
#if UNIX
|
||||
this._user = Platform.Unix.UserName;
|
||||
this._user = Environment.UserName;
|
||||
#else
|
||||
this._user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
|
||||
this._user = Environment.UserDomainName + "\\" + Environment.UserName;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -2768,9 +2768,9 @@ namespace System.Management.Automation.Runspaces
|
||||
? this.UserDriveUserName
|
||||
// domain\user on Windows, just user on Unix
|
||||
#if UNIX
|
||||
: Platform.Unix.UserName;
|
||||
: Environment.UserName;
|
||||
#else
|
||||
: System.Security.Principal.WindowsIdentity.GetCurrent().Name;
|
||||
: Environment.UserDomainName + "_" + Environment.UserName;
|
||||
#endif
|
||||
|
||||
// Ensure that user name contains no invalid path characters.
|
||||
@@ -2781,7 +2781,7 @@ namespace System.Management.Automation.Runspaces
|
||||
throw new PSInvalidOperationException(RemotingErrorIdStrings.InvalidUserDriveName);
|
||||
}
|
||||
|
||||
return userName.Replace("\\", "_");
|
||||
return userName;
|
||||
}
|
||||
|
||||
private Exception ProcessStartupScripts(Runspace initializedRunspace)
|
||||
|
||||
@@ -36,8 +36,7 @@ namespace PSTests.Parallel
|
||||
|
||||
// The process should return an exit code of 0 on success
|
||||
Assert.Equal(0, process.ExitCode);
|
||||
// It should be the same as what our platform code returns
|
||||
Assert.Equal(username, Platform.Unix.UserName());
|
||||
Assert.Equal(username, Environment.UserName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user