8000 Don't allow `Move-Item` with FileSystemProvider to move a directory into itself by SteveL-MSFT · Pull Request #16198 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@SteveL-MSFT
Copy link
Member
@SteveL-MSFT SteveL-MSFT commented Oct 5, 2021

PR Summary

Add an explicit check that the destination path is not a subdirectory of the source path.

PR Context

When DirectoryInfo.MoveTo() is used and the destination is a subfolder of the source, an Access Denied exception is returned. However, the error code for this cannot be differentiated from other Access Denied cases like you don't have permission for the destination or across DFS volumes. So the FileSystemProvider falls back to CopyAndDelete() to handle this case. However, for this scenario, this results in infinite recursion.

Since you can't move a parent into a child path, it makes sense to check for this condition and return an error. This is a regression from 7.1 due to other changes needed for FileSystemProvider to fix other Move-item behavior.

PR Checklist

Copy link
Contributor
@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adityapatwardhan adityapatwardhan merged commit d0e8237 into PowerShell:master Oct 12, 2021
@adityapatwardhan adityapatwardhan added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 12, 2021
@adityapatwardhan adityapatwardhan added this to the 7.2.0-rc.1 milestone Oct 12, 2021
@SteveL-MSFT SteveL-MSFT deleted the move-item-3 branch October 12, 2021 23:47
daxian-dbw pushed a commit to daxian-dbw/PowerShell that referenced this pull request Oct 21, 2021
@ghost
Copy link
ghost commented Oct 21, 2021

🎉v7.2.0-rc.1 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link
ghost commented Dec 16, 2021

🎉v7.3.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.2.x-Done CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

0