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: 0 additions & 38 deletions src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,40 +573,6 @@ internal static ErrorCategory GetErrorCategory(int errno)
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
Expand Down Expand Up @@ -669,10 +635,6 @@ internal static class NativeMethods
[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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public string User
{
// 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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2768,9 +2768,9 @@ private string MakeUserNamePath()
? 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.
Expand All @@ -2781,7 +2781,7 @@ private string MakeUserNamePath()
throw new PSInvalidOperationException(RemotingErrorIdStrings.InvalidUserDriveName);
}

return userName.Replace("\\", "_");
return userName;
}

private Exception ProcessStartupScripts(Runspace initializedRunspace)
Expand Down
3 changes: 1 addition & 2 deletions test/xUnit/csharp/test_CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public static void TestGetUserName()

// 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);
}
}

Expand Down