mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
New-Item -ItemType SymbolicLink cannot understand directory path ending with slash on Linux (#2974)
This commit is contained in:
committed by
Mike Richmond
parent
79a1f80309
commit
e3d4c95a77
@@ -9,6 +9,7 @@ using System.Management.Automation.Runspaces;
|
||||
using System.Management.Automation.Internal;
|
||||
using System.Reflection;
|
||||
using Dbg = System.Management.Automation;
|
||||
using System.IO;
|
||||
|
||||
#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings
|
||||
#pragma warning disable 56500
|
||||
@@ -3689,10 +3690,17 @@ namespace System.Management.Automation
|
||||
|
||||
foreach (string path in paths)
|
||||
{
|
||||
string resolvePath = null;
|
||||
if (path == null)
|
||||
{
|
||||
PSTraceSource.NewArgumentNullException("paths");
|
||||
}
|
||||
else
|
||||
{
|
||||
// To be compatible with Linux OS. Which will be either '/' or '\' depends on the OS type.
|
||||
char[] charsToTrim = {' ', Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar};
|
||||
resolvePath = path.TrimEnd(charsToTrim);
|
||||
}
|
||||
|
||||
ProviderInfo provider = null;
|
||||
PSDriveInfo driveInfo;
|
||||
@@ -3705,7 +3713,7 @@ namespace System.Management.Automation
|
||||
if (String.IsNullOrEmpty(name))
|
||||
{
|
||||
string providerPath =
|
||||
Globber.GetProviderPath(path, context, out provider, out driveInfo);
|
||||
Globber.GetProviderPath(resolvePath, context, out provider, out driveInfo);
|
||||
|
||||
providerInstance = GetProviderInstance(provider);
|
||||
providerPaths.Add(providerPath);
|
||||
@@ -3714,7 +3722,7 @@ namespace System.Management.Automation
|
||||
{
|
||||
providerPaths =
|
||||
Globber.GetGlobbedProviderPathsFromMonadPath(
|
||||
path,
|
||||
resolvePath,
|
||||
true,
|
||||
context,
|
||||
out provider,
|
||||
|
||||
@@ -186,4 +186,10 @@ Describe "New-Item with links" -Tags @('CI', 'RequireAdminOnWindows') {
|
||||
$_.FullyQualifiedErrorId | Should Be "NewItemSymbolicLinkElevationRequired,Microsoft.PowerShell.Commands.NewItemCommand"
|
||||
}
|
||||
}
|
||||
|
||||
It "New-Item -ItemType SymbolicLink should understand directory path ending with slash" {
|
||||
$folderName = [System.IO.Path]::GetRandomFileName()
|
||||
$symbolicLinkPath = New-Item -ItemType SymbolicLink -Path "$tmpDirectory/$folderName/" -Value "/bar/"
|
||||
$symbolicLinkPath | Should Not Be $null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user