Fix `Move-Item` to error when moving into itself by SteveL-MSFT · Pull Request #24004 · PowerShell/PowerShell · GitHub
Skip to content

Fix Move-Item to error when moving into itself#24004

Merged
daxian-dbw merged 3 commits intoPowerShell:masterfrom
SteveL-MSFT:move-item-itself
Jul 8, 2024
Merged

Fix Move-Item to error when moving into itself#24004
daxian-dbw merged 3 commits intoPowerShell:masterfrom
SteveL-MSFT:move-item-itself

Conversation

@SteveL-MSFT
Copy link
Copy Markdown
Member

@SteveL-MSFT SteveL-MSFT commented Jul 1, 2024

PR Summary

There is an edge case where the source has a trailing directory separator that isn't handled and falls through which results in the src empty folder being deleted:

move-item ./empty/

The fix is to add an additional check to handle the case where the src and destination is the same, but differs by the src trailing separator.

PR Context

Fix #23996

PR Checklist

@SteveL-MSFT SteveL-MSFT requested a review from anmenaga as a code owner July 1, 2024 17:35
@SteveL-MSFT SteveL-MSFT requested a review from JamesWTruher July 1, 2024 21:48
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there already a test for ./Empty (to avoid regressions)?

Could the test name be more specific like Verify Move-Item don't allow moving a directory into itself or its sub-directory?

@daxian-dbw daxian-dbw enabled auto-merge (squash) July 8, 2024 23:23
@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jul 8, 2024
@daxian-dbw daxian-dbw merged commit 2d83b95 into PowerShell:master Jul 8, 2024
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

microsoft-github-policy-service Bot commented Jul 8, 2024

chrisdent-de pushed a commit to chrisdent-de/PowerShell that referenced this pull request Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Move-Item should not delete empty folders when missing destination

3 participants