Repository navigation
Closed
Labels
Description
Summary
Just started using PowerShell core on Linux and its fantastic so far! I can across an interesting bug regarding the Move-Item cmdlet. If I'm on the same mount point, it works as expected but if I'm moving items from one Mount to another it errors with a cross device link error.
Copy-Item is able to copy across devices as a work around. See below for details.
Hopefully this can get fixed in the 7.1 release.
Steps to reproduce
# Note: Source and destinations must be on different mounts shown by the "df" command.
$Source=/tmp/files/*
$Destination=/etc/files/
Move-Item $Source $DestinationExpected behavior
Files are removed from the source and exist at the destiation.
Actual behavior
Red Error Message:
Move-Item: Invalid cross-device link
Environment data
$PSVersionTable:
Name Value
---- -----
PSVersion 7.0.2
PSEdition Core
GitCommitId 7.0.2
OS Linux 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Other System Information:
Operating System: CentOS Linux release 7.8.2003 (Core)
UNAME: Linux op2-snf-ldev4.cgifederal.com 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
System Mounts:
Filesystem Type 1K-blocks Used Available Use% Mounted on
devtmpfs devtmpfs 3987736 0 3987736 0% /dev
tmpfs tmpfs 4004528 0 4004528 0% /dev/shm
tmpfs tmpfs 4004528 9768 3994760 1% /run
tmpfs tmpfs 4004528 0 4004528 0% /sys/fs/cgroup
/dev/mapper/centos_root xfs 5232640 181832 5050808 4% /
/dev/mapper/centos_usr xfs 8378368 4752188 3626180 57% /usr
/dev/sda1 xfs 1038336 298172 740164 29% /boot
/dev/mapper/centos_tmp xfs 8378368 183096 8195272 3% /tmp
/dev/mapper/centos_home xfs 157209600 185644 157023956 1% /home
/dev/mapper/centos_var xfs 8378368 3279240 5099128 40% /var
/dev/mapper/centos_opt xfs 209612800 16759668 192853132 8% /opt
/dev/mapper/centos_var--lib xfs 8378368 428752 7949616 6% /var/lib
tmpfs tmpfs 800908 12 800896 1% /run/user/42
tmpfs tmpfs 800908 0 800908 0% /run/user/1391052081
Note that LVM is used on this system, not sure if that's causing cross-device linking issues or not.
Current Work Around
I am able to Copy-Item and then Remove-Item. This only impacts Move-Item for some reason.
Copy-Item $Source $Destination -Recurse
Remove-Item $Source
Activity
rjmholt commentedon Jun 26, 2020
The full error message would help a lot more here. You can get this with
Get-Error[-]My bug report[/-][+]Move-Item does not work across mounts on Linux[/+]rjmholt commentedon Jun 27, 2020
I have a repro:
rjmholt commentedon Jun 27, 2020
Looks like this happens here, and the cause for the error is in the Unix implementation here, which uses the rename syscall.
This occurs because
renamedoes not support renaming across filesystems.The
mvcoreutil handles this by tryingrenamefirst but if not, copying the file and deleting it later.Unsure if .NET would consider this a bug, but the solution for us is probably to do the same as
mv. It turns out we already try to do this:PowerShell/src/System.Management.Automation/namespaces/FileSystemProvider.cs
Lines 5991 to 5999 in 9212aac
But the test we use is primitive and Windows-specific:
PowerShell/src/System.Management.Automation/namespaces/FileSystemProvider.cs
Lines 6097 to 6103 in 9212aac
We should improve this test to distinguish Unix mounts.
iSazonov commentedon Jun 29, 2020
.Net uses MOVEFILE_COPY_ALLOWED flag for MoveFileEx() and this works cross volumes.
For Unixes it should be fixed in .Net. Please vote in dotnet/runtime#31149
iSazonov commentedon Jul 7, 2020
Rob Holt (@rjmholt) Dongbo Wang (@daxian-dbw) Will we keep the issue open and track dotnet/runtime#31149?
rjmholt commentedon Jul 7, 2020
I've opened #13126 to track that