Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e5d48d5
Update SessionStateContainer.cs
GameMicrowave Mar 16, 2025
01d9d48
Update regex.cs
GameMicrowave Mar 16, 2025
4698a65
Update FileSystemProvider.cs
GameMicrowave Mar 16, 2025
d2abc6a
Update FileSystemProvider.cs
GameMicrowave Mar 16, 2025
75793c5
Merge branch 'master' into master
GameMicrowave Mar 17, 2025
7bdd169
Merge branch 'master' into master
GameMicrowave Mar 17, 2025
3cd5e94
Merge branch 'master' into master
GameMicrowave Mar 18, 2025
ba8c3a5
Merge branch 'master' into master
GameMicrowave Mar 22, 2025
c939b5d
Update regex.cs
GameMicrowave Mar 23, 2025
e5fd38f
Merge branch 'master' into master
GameMicrowave Mar 24, 2025
11394f7
Merge branch 'master' into master
GameMicrowave Mar 25, 2025
49b2e6b
Update FileSystemProvider.cs
GameMicrowave Mar 25, 2025
9a05773
Update New-Item.Tests.ps1
GameMicrowave Mar 25, 2025
119cf31
Update New-Item.Tests.ps1
GameMicrowave Mar 25, 2025
edce71b
Update SessionStateContainer.cs
GameMicrowave Mar 25, 2025
5f1c651
Merge branch 'master' into master
GameMicrowave Mar 25, 2025
f505d02
Update New-Item.Tests.ps1
GameMicrowave Mar 25, 2025
6e5662f
Update New-Item.Tests.ps1
GameMicrowave Mar 26, 2025
9bf16b3
Update FileSystemProvider.cs
GameMicrowave Mar 26, 2025
b6be73d
Merge branch 'master' into master
GameMicrowave Mar 26, 2025
6bb4851
Update New-Item.Tests.ps1
GameMicrowave Mar 26, 2025
c46d1c3
Merge branch 'master' into master
GameMicrowave Mar 30, 2025
2e384ae
Merge branch 'master' into master
GameMicrowave Apr 2, 2025
ed99aff
Update GroupPolicySettings.Tests.ps1
GameMicrowave Apr 2, 2025
785942c
Update GroupPolicySettings.Tests.ps1
GameMicrowave Apr 2, 2025
e6c321e
Merge branch 'master' into master
GameMicrowave Apr 2, 2025
75fb01c
Merge branch 'master' into master
GameMicrowave Apr 2, 2025
895e033
Merge branch 'master' into master
GameMicrowave Apr 3, 2025
f2288f4
Update New-Item.Tests.ps1
GameMicrowave Apr 4, 2025
4e0c3b5
Merge branch 'master' into master
GameMicrowave Apr 4, 2025
46e9ebb
Update New-Item.Tests.ps1
GameMicrowave Apr 4, 2025
63791f6
Update New-Item.Tests.ps1
GameMicrowave Apr 4, 2025
0587ff1
Merge branch 'master' into master
GameMicrowave Apr 4, 2025
1544d46
Merge branch 'master' into master
GameMicrowave Apr 9, 2025
e484f9f
Update FileSystemProvider.cs
GameMicrowave Apr 10, 2025
e8cf8f8
Merge branch 'master' into master
GameMicrowave Apr 12, 2025
06b4828
Merge branch 'master' into master
GameMicrowave Apr 18, 2025
158478d
Merge branch 'master' into master
GameMicrowave Apr 28, 2025
bf37892
Merge branch 'master' into master
GameMicrowave Apr 28, 2025
ddf75cd
Update New-Item.Tests.ps1
GameMicrowave May 1, 2025
2f745dd
Update FileSystem.Tests.ps1
GameMicrowave May 1, 2025
ce42c91
Update FileSystem.Tests.ps1
GameMicrowave May 1, 2025
54ab8a4
Merge branch 'master' into master
GameMicrowave May 1, 2025
4fb6044
Update FileSystem.Tests.ps1
GameMicrowave May 1, 2025
b0dbfca
Update FileSystem.Tests.ps1
GameMicrowave May 1, 2025
01bf445
Update FileSystem.Tests.ps1
GameMicrowave May 1, 2025
fccb190
Merge branch 'master' into master
GameMicrowave May 10, 2025
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
32 changes: 1 addition & 31 deletions src/System.Management.Automation/engine/SessionStateContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3497,37 +3497,7 @@ internal void NewItem(
throw PSTraceSource.NewArgumentNullException(nameof(content), SessionStateStrings.NewLinkTargetNotSpecified, path);
}

ProviderInfo targetProvider = null;
CmdletProvider targetProviderInstance = null;

var globbedTarget = Globber.GetGlobbedProviderPathsFromMonadPath(
targetPath,
allowNonexistingPath,
context,
out targetProvider,
out targetProviderInstance);

if (!string.Equals(targetProvider.Name, "filesystem", StringComparison.OrdinalIgnoreCase))
{
throw PSTraceSource.NewNotSupportedException(SessionStateStrings.MustBeFileSystemPath);
}

if (globbedTarget.Count > 1)
{
throw PSTraceSource.NewInvalidOperationException(SessionStateStrings.PathResolvedToMultiple, targetPath);
}

if (globbedTarget.Count == 0)
{
throw PSTraceSource.NewInvalidOperationException(SessionStateStrings.PathNotFound, targetPath);
}

// If the original target was a relative path, we want to leave it as relative if it did not require
// globbing to resolve.
if (WildcardPattern.ContainsWildcardCharacters(targetPath))
{
content = globbedTarget[0];
}
content = targetPath;
}

NewItemPrivate(providerInstance, composedPath, type, content, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2271,8 +2271,7 @@ protected override void NewItem(
// for hardlinks we resolve the target to an absolute path
if (!IsAbsolutePath(strTargetPath))
{
// there is already a check before here so that strTargetPath should only resolve to 1 path
strTargetPath = SessionState.Path.GetResolvedPSPathFromPSPath(strTargetPath).FirstOrDefault()?.Path;
strTargetPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(strTargetPath);
}

exists = GetFileSystemInfo(strTargetPath, out isDirectory) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,12 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
}
}

$realFile = Join-Path $TestPath "file.txt"
# Ensure that the file link can still be successfully created when the target file/directory name contains wildcards.
$realFile = Join-Path $TestPath "[file].txt"
$nonFile = Join-Path $TestPath "not-a-file"
$fileContent = "some text"
$realDir = Join-Path $TestPath "subdir"
$realDir2 = Join-Path $TestPath "second-subdir"
$realDir = Join-Path $TestPath "[subdir]"
$realDir2 = Join-Path $TestPath "[second-subdir]"
$nonDir = Join-Path $TestPath "not-a-dir"
$hardLinkToFile = Join-Path $TestPath "hard-to-file.txt"
$symLinkToFile = Join-Path $TestPath "sym-link-to-file.txt"
Expand All @@ -626,7 +627,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
Context "New-Item and hard/symbolic links" {
AfterEach {
# clean up created links after each test
Remove-Item -Exclude (Split-Path -Leaf $realFile, $realDir, $realDir2) -Recurse $TestPath/*
Remove-Item -Exclude (Split-Path -Leaf ([WildcardPattern]::Escape($realFile)), ([WildcardPattern]::Escape($realDir)), ([WildcardPattern]::Escape($realDir2))) -Recurse $TestPath/*
}

It "New-Item can create a hard link to a file" {
Expand All @@ -639,7 +640,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
It "New-Item can create symbolic link to file" {
New-Item -ItemType SymbolicLink -Path $symLinkToFile -Value $realFile > $null
Test-Path $symLinkToFile | Should -BeTrue
$real = Get-Item -Path $realFile
$real = Get-Item -LiteralPath $realFile
$link = Get-Item -Path $symLinkToFile
$link.LinkType | Should -BeExactly "SymbolicLink"
$link.Target | Should -BeExactly $real.ToString()
Expand All @@ -658,15 +659,15 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
It "New-Item can create a symbolic link to a directory" -Skip:($IsWindows) {
New-Item -ItemType SymbolicLink -Path $symLinkToDir -Value $realDir > $null
Test-Path $symLinkToDir | Should -BeTrue
$real = Get-Item -Path $realDir
$real = Get-Item -LiteralPath $realDir
$link = Get-Item -Path $symLinkToDir
$link.LinkType | Should -BeExactly "SymbolicLink"
$link.Target | Should -BeExactly $real.ToString()
}
It "New-Item can create a directory symbolic link to a directory" -Skip:(-Not $IsWindows) {
New-Item -ItemType SymbolicLink -Path $symLinkToDir -Value $realDir > $null
Test-Path $symLinkToDir | Should -BeTrue
$real = Get-Item -Path $realDir
$real = Get-Item -LiteralPath $realDir
$link = Get-Item -Path $symLinkToDir
$link | Should -BeOfType System.IO.DirectoryInfo
$link.LinkType | Should -BeExactly "SymbolicLink"
Expand All @@ -677,7 +678,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
$target = Split-Path -Leaf $realDir
New-Item -ItemType SymbolicLink -Path $symLinkToDir -Value $target > $null
Test-Path $symLinkToDir | Should -BeTrue
$real = Get-Item -Path $realDir
$real = Get-Item -LiteralPath $realDir
$link = Get-Item -Path $symLinkToDir
$link | Should -BeOfType System.IO.DirectoryInfo
$link.LinkType | Should -BeExactly "SymbolicLink"
Expand All @@ -689,7 +690,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
$target = ".\$(Split-Path -Leaf $realDir)"
New-Item -ItemType SymbolicLink -Path $symLinkToDir -Value $target > $null
Test-Path $symLinkToDir | Should -BeTrue
$real = Get-Item -Path $realDir
$real = Get-Item -LiteralPath $realDir
$link = Get-Item -Path $symLinkToDir
$link | Should -BeOfType System.IO.DirectoryInfo
$link.LinkType | Should -BeExactly "SymbolicLink"
Expand Down Expand Up @@ -732,8 +733,8 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
}

It "New-Item -Force can overwrite a junction" -Skip:(-Not $IsWindows){
$rd2 = Get-Item -Path $realDir2
New-Item -Name testfile.txt -ItemType file -Path $realDir
$rd2 = Get-Item -LiteralPath $realDir2
New-Item -Name testfile.txt -ItemType file -Path ([WildcardPattern]::Escape($realDir))
New-Item -ItemType Junction -Path $junctionToDir -Value $realDir > $null
Test-Path $junctionToDir | Should -BeTrue
{ New-Item -ItemType Junction -Path $junctionToDir -Value $realDir -ErrorAction Stop > $null } | Should -Throw -ErrorId "DirectoryNotEmpty,Microsoft.PowerShell.Commands.NewItemCommand"
Expand Down Expand Up @@ -879,7 +880,7 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"

Remove-Item -Path $Link -ErrorAction SilentlyContinue > $null
Test-Path -Path $Link | Should -BeFalse
Test-Path -Path $Target | Should -BeTrue
Test-Path -LiteralPath $Target | Should -BeTrue
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/powershell/engine/Basic/GroupPolicySettings.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe 'Group policy settings tests' -Tag CI,RequireAdminOnWindows {
Describe 'Group policy settings tests' -Tags @('CI', 'RequireAdminOnWindows') {
BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
if ( ! $IsWindows ) {
Expand Down
Loading