Skip to content

Remove-Item -Recurse on symlink should recurse when path ends with path separator #3674

@jeffbi

Description

@jeffbi

Part of the resolution of issue #621 was to have the -Recurse option be ignored when removing a symlink to a directory with a command such as Remove-Item -Recurse -Path linktodir, to be more in line with the unix Unix rm command.

However, on Unix the rm command, when given as rm -r linktodir/', with the trailing slash on the pathname, *will* recurse into the target directory and delete its contents, then remove the link, leaving the target directory behind. Without the trailing slash rm -r linktodir` simply removes the link.

Steps to reproduce

New-Item -ItemType Directory subdir
New-Item subdir/file.txt
New-Item -ItemType SymbolicLink link-to-sub -value subdir
Remove-Item -Recurse link-to-sub/

Expected behavior

Symbolic link link-to-sub should be deleted, directory subdir should still exist but be empty.

Actual behavior

On Linux, the directory subdir is emptied and remains, but an error is emitted and the symbolic link is not deleted. Error is Not a directory.

On Windows, the symbolic link is deleted but the directory subdir and its contents remain.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
BuildVersion                   3.0.0.0
CLRVersion
GitCommitId                    v6.0.0-alpha.18-33-ged4e77d65809ed8ee2589fd50...
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSEdition                      Core
PSRemotingProtocolVersion      2.3
PSVersion                      6.0.0-alpha
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerIssue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management moduleWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions