-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
(This was found when I was testing my PR #13650 written to address bug #10570. It had not been found before because there are no unit tests for alternate data stream handling on filesystems which do not support alternate data streams.)
The issue: The cmdlets in System.Management.Automation/Microsoft.Powershell.Commands.FileSystemProvider have the parameter -Path which takes an array of directories to process. The -Stream parameter can throw terminating errors which terminate the processing of the remainder of the -Path array.
This makes script authors need to manually loop over candidate arrays they might wish to pass to the FileSystemProvider cmdlets, which ignores the reason non-terminating errors exist in the first place.
The correct action is to change the thrown terminating errors to WriteError() non-terminating errors in all places GetStreams() is called. (It cannot be fixed within GetStreams itself, because it's not in a cmdlet implementation object and so doesn't have a WriteError implementation available.)
PS D:\test> get-item m:\*,d:\test\* -Stream *
Get-Item: Alternate data streams are not supported for the specified path.
PS D:\test> get-item d:\test\*,m:\* -Stream *
PSPath : Microsoft.PowerShell.Core\FileSystem::D:\test\testfile::$DATA
PSParentPath : Microsoft.PowerShell.Core\FileSystem::D:\test
PSChildName : testfile::$DATA
PSDrive : D
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
FileName : D:\test\testfile
Stream : :$DATA
Length : 0
PSPath : Microsoft.PowerShell.Core\FileSystem::D:\test\testfile:teststream
PSParentPath : Microsoft.PowerShell.Core\FileSystem::D:\test
PSChildName : testfile:teststream
PSDrive : D
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
FileName : D:\test\testfile
Stream : teststream
Length : 0
PSPath : Microsoft.PowerShell.Core\FileSystem::D:\test\whatever.txt::$DATA
PSParentPath : Microsoft.PowerShell.Core\FileSystem::D:\test
PSChildName : whatever.txt::$DATA
PSDrive : D
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
FileName : D:\test\whatever.txt
Stream : :$DATA
Length : 28
PSPath : Microsoft.PowerShell.Core\FileSystem::D:\test\whatever.txt:$DATA
PSParentPath : Microsoft.PowerShell.Core\FileSystem::D:\test
PSChildName : whatever.txt:$DATA
PSDrive : D
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
FileName : D:\test\whatever.txt
Stream : $DATA
Length : 36
Get-Item: Alternate data streams are not supported for the specified path.
PS D:\test>