Skip to content

Copy-Item does not understand symlinks #2957

@andyleejordan

Description

@andyleejordan

Steps to reproduce

~/test |-/ mkdir folder
~/test |-/ touch file
~/test |-/ ln -s folder validfolderlink
~/test |-/ ln -s file validfilelink
~/test |-/ ln -s foobarbaz brokenlink
~/test |-/ Copy-Item ./validfolderlink validfolderlinkcopy
~/test |-/ ls -l validfolderlinkcopy
total 0
~/test |-/ Copy-Item ./validfilelink validfilelinkcopy
~/test |-/ ls -l ./validfilelinkcopy
-rw-rw-r--. 1 andschwa andschwa 0 Jan  5 13:29 ./validfilelinkcopy
~/test |-/ Copy-Item ./brokenlink brokenlinkcopy
Copy-Item : Could not find file '/home/andschwa/test/brokenlink'.
At line:1 char:1
+ Copy-Item ./brokenlink brokenlinkcopy
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand

~/test |-/

Expected behavior

  1. validfolderlinkcopy should be a copy of the symlink validfolderlink
  2. validfilelinkcopy should be a copy of the symlink validfilelink
  3. brokenlinkcopy should be a copy of the symlink brokenlink

Actual behavior

  1. validfolderlinkcopy is a copy of link's target folder
  2. validfilelinkcopy is a copy of the link's target file
  3. PowerShell throws an error when copying brokenlink to brokenlinkcopy

Environment data

> $PSVersionTable
v6.0.0-alpha.14
> uname -nro
andschwa-centos 3.10.0-514.2.2.el7.x86_64 GNU/Linux

This is similar to #804 where New-Item did not understand broken symlinks, since it was trying to follow it. The semantics on Linux of copy/move/new is to treat the symlink as a normal file, instead of following it, but PowerShell does not do this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions