8000 Do not reject Windows' reserved device names on non-Windows platforms. by jeffbi · Pull Request #3252 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 2 commits into from
Mar 7, 2017
Merged

Do not reject Windows' reserved device names on non-Windows platforms. #3252

merged 2 commits into from
Mar 7, 2017

Conversation

jeffbi
Copy link
Contributor
@jeffbi jeffbi commented Mar 3, 2017

Fixes #3221

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"
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member
@daxian-dbw daxian-dbw Mar 7, 2017

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
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member
@daxian-dbw daxian-dbw Mar 7, 2017

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
Copy link
Member
@daxian-dbw daxian-dbw Mar 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here. #Closed

@daxian-dbw daxian-dbw self-assigned this Mar 5, 2017
$newFile = Copy-Item -Path $testFile -Destination $deviceName -PassThru
$fileExists = Test-Path $deviceName
$fileExists | Should Be $true
$newFile.Name | Should Be $deviceName
Copy link
Collaborator

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.

Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Collaborator

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"

Copy link
Contributor Author

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
Copy link
Collaborator

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#Closed.

@daxian-dbw daxian-dbw merged commit 97be759 into PowerShell:master Mar 7, 2017
@jeffbi jeffbi deleted the reserved-device-names branch March 7, 2017 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0