mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 20:56:02 +00:00
Fix Move-Item to support cross-mount moves on Unix (#13044)
This commit is contained in:
1 parent
8ad954d285
commit
d3addeb3da
3 files changed
+78
-18
No files matched your search
@@ -131,12 +131,36 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
|
||||
"$destDir/$testDir/$testFile" | Should -Exist
|
||||
}
|
||||
|
||||
It "Verify Move-Item across devices for directory" {
|
||||
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('ThrowExdevErrorOnMoveDirectory', $true)
|
||||
try
|
||||
{
|
||||
$dir = (New-Item -Path TestDrive:/dir -ItemType Directory -ErrorAction Stop).FullName
|
||||
$file = (New-Item -Path "$dir/file.txt" -Value "HELLO" -ErrorAction Stop).Name
|
||||
$destination = "$TestDrive/destination"
|
||||
|
||||
Move-Item -Path $dir -Destination $destination -ErrorAction Stop
|
||||
|
||||
$dir | Should -Not -Exist
|
||||
$destination | Should -Exist
|
||||
"$destination/$file" | Should -Exist
|
||||
}
|
||||
finally
|
||||
{
|
||||
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('ThrowExdevErrorOnMoveDirectory', $false)
|
||||
}
|
||||
}
|
||||
|
||||
It "Verify Move-Item will not move to an existing file" {
|
||||
{ Move-Item -Path $testDir -Destination $testFile -ErrorAction Stop } | Should -Throw -ErrorId "MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand"
|
||||
$error[0].Exception | Should -BeOfType System.IO.IOException
|
||||
$testDir | Should -Exist
|
||||
}
|
||||
|
||||
It "Verify Move-Item throws correct error for non-existent source" {
|
||||
{ Move-Item -Path /does/not/exist -Destination $testFile -ErrorAction Stop } | Should -Throw -ErrorId 'PathNotFound,Microsoft.PowerShell.Commands.MoveItemCommand'
|
||||
}
|
||||
|
||||
It "Verify Move-Item as substitute for Rename-Item" {
|
||||
$newFile = Move-Item -Path $testFile -Destination $newTestFile -PassThru
|
||||
$fileExists = Test-Path $newTestFile
|
||||
|
||||
Reference in new issue
Block a user