Skip to content
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

'Copy-Item -Recursive <source folder> <target folder>' doesn't copy symlink as 'cp -r' does on Linux #5240

Open
daxian-dbw opened this issue Oct 25, 2017 · 1 comment
Labels
Area-FileSystem-Provider specific to the FileSystem provider WG-Cmdlets-Management cmdlets in the Microsoft.PowerShell.Management module

Comments

@daxian-dbw
Copy link
Member

Steps to reproduce

echo test > /tmp/test.txt
mkdir /tmp/source > $null
New-Item -Force -ItemType SymbolicLink -Target /tmp/test.txt -Path /tmp/source/link > $null
Copy-Item -Recurse /tmp/source /tmp/dest
cp -r /tmp/source /tmp/dest2

Expected behavior

Copy-Item -Recursive should copy the symbolic link to /tmp/dest, just like cp -r

ls /tmp/dest -l
link -> /tmp/test.txt

Actual behavior

bash:80> ls /tmp/dest -l
total 4
-rw-rw-r-- 1 auser auser 12 Oct 25 16:30 link
bash:81> ls /tmp/dest2 -l
total 0
lrwxrwxrwx 1 auser auser 13 Oct 25 16:32 link -> /tmp/test.txt

Environment data

> $PSVersionTable
Name                           Value                                                               
----                           -----                                                               
PSVersion                      6.0.0-beta.8                                                        
PSEdition                      Core                                                                
GitCommitId                    v6.0.0-beta.8                                                       
OS                             Linux 4.10.0-37-generic #41~16.04.1-Ubuntu SMP Fri Oct 6 22:42:59...
Platform                       Unix                                                                
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                             
PSRemotingProtocolVersion      2.3                                                                 
SerializationVersion           1.1.0.1                                                             
WSManStackVersion              3.0   
@daxian-dbw daxian-dbw added the WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc. label Oct 25, 2017
@iSazonov iSazonov added Area-FileSystem-Provider specific to the FileSystem provider WG-Cmdlets-Management cmdlets in the Microsoft.PowerShell.Management module and removed WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc. labels Nov 30, 2021
@mklement0
Copy link
Contributor

That is indeed problematic.

cp -R's (sensible) default behavior, as you've shown, is to copy symlinks as links, instead of copying their targets, which with directory targets could result in a lot of unwanted content getting copied.
Wanting to copy link targets requires opt-in via -L, for instance.

While on Windows this default behavior is unfortunately reversed in xcopy.exe and robocopy.exe, these utilities at least offer opt-ins for copying links as such: /B and /SL, respectively.

It looks like, due to its age, this issue has fallen through the cracks; please label it appropriately so it can be revived.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FileSystem-Provider specific to the FileSystem provider WG-Cmdlets-Management cmdlets in the Microsoft.PowerShell.Management module
Projects
None yet
Development

No branches or pull requests

3 participants