-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Do not reject Windows' reserved device names on non-Windows platforms. #3252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It "Copy-Item rejects Windows reserved device names" -Skip:(-not $IsWindows) { | ||
foreach ($deviceName in $reservedNames) | ||
{ | ||
{ Copy-Item -Path $testFile -Destination $deviceName -ErrorAction Stop } | ShouldBeErrorId "CopyError,Microsoft.PowerShell.Commands.CopyItemCommand" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a more specific check that it failed because of reserved name vs something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current code throws an IOException with a localized string as its message, and uses "CopyError" ("MoveError"/"RenameError") in the error record.
We could modify the error ID in the error record to say something like "CopyToReservedNameError", with "MoveTo" and "RenameTo" versions, if that wouldn't badly impact existing user code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is in common function PathIsReservedDeviceName
We could make new specific IOException but is it worth?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not worth it then.
It "Move-Item succeeds with Windows reserved device names" -Skip:($IsWindows) { | ||
foreach ($deviceName in $reservedNames) | ||
{ | ||
Copy-Item -Path $testFile -Destination $tempFile -Force |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$tempFile
seems not necessary in these tests. $testFile
is created in BeforeEach
and removed in AfterEach
, so you can use testFile
directly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Move-Item and Rename-Item the $tempFile was to be able to restore $testFile each time through the foreach across device names. I can certainly use New-Item to create a new $testFile each iteration if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. It's in a loop. Ignore my comment. #Closed
Copy-Item -Path $testFile -Destination $tempFile -Force | ||
$newFile = Move-Item -Path $testFile -Destination $deviceName -PassThru | ||
$fileExists = Test-Path $deviceName | ||
$fileExists | Should Be $true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just Test-Path $deviceName | Should Be $true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just keeping consistency with existing tests. I'm happy to make this change. Should I do so for the pre-existing tests as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. You can submit a new PR later to address that particular issue. #Closed
Copy-Item -Path $testFile -Destination $tempFile -Force | ||
$newFile = Rename-Item -Path $testFile -NewName $deviceName -PassThru | ||
$fileExists = Test-Path $deviceName | ||
$fileExists | Should Be $true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here. #Closed
$newFile = Copy-Item -Path $testFile -Destination $deviceName -PassThru | ||
$fileExists = Test-Path $deviceName | ||
$fileExists | Should Be $true | ||
$newFile.Name | Should Be $deviceName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose that's enough:
Copy-Item -Path $testFile -Destination $deviceName -Force -ErrorAction SilentlyContinue
Test-Path $deviceName | Should Be $true
The same for tests below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeffbi It would be great if you can address this comment, but it doesn't block merging this PR in case you want to address it later for all existing tests in this file. Please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've addressed @iSazonov's comments here. I'll put off changing the previously existing tests.
} | ||
} | ||
|
||
It "Copy-Item succeeds with Windows reserved device names" -Skip:($IsWindows) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe more specifically:
"Copy-Item succeeds on Unix with Windows reserved device names"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree. I'll change that.
It "Move-Item on Unix succeeds with Windows reserved device names" -Skip:($IsWindows) { | ||
foreach ($deviceName in $reservedNames) | ||
{ | ||
Copy-Item -Path $testFile -Destination $tempFile -Force |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe really use New-Item
here? The code will be more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#Closed.
Fixes #3221