KEMBAR78
Use absolute path in `FileSystemProvider.CreateDirectory` by Tadas · Pull Request #24615 · PowerShell/PowerShell · GitHub
Skip to content

Conversation

@Tadas
Copy link
Contributor

@Tadas Tadas commented Nov 23, 2024

PR Summary

Remove unnecessary path split in FileSystemProvider.CreateDirectory because those parts are not used anywhere and ultimately end up being combined again for the Directory.CreateDirectory call.

PR Context

Fixes pester/Pester#2258 :

When invoking the New-Item cmdlet with a path of TestDrive:\ -Force during a test, a new folder in the current working directory with the name of the guid of the TestDrive: provider is created.

PR Checklist

@Tadas Tadas requested a review from anmenaga as a code owner November 23, 2024 18:32
@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Dec 7, 2024
@Tadas Tadas requested a review from iSazonov February 1, 2025 09:29
@iSazonov iSazonov requested review from SteveL-MSFT and removed request for anmenaga February 1, 2025 17:28
@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Feb 1, 2025
@iSazonov iSazonov self-assigned this Feb 1, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Feb 1, 2025
iSazonov
iSazonov previously approved these changes Feb 7, 2025
Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

LGTM.
The .Net method Directory.CreateDirectory(path) works right only if path is absolute path, otherwise the path is considered as relative one based on system CWD.
If we call GetParentPath(path, null) the method uses a root path for current psdrive, i.e. we calculate relative path but we need absolute path.
So the call looks like a bug for all (5) code paths where the void CreateDirectory() method is used.

@iSazonov
Copy link
Collaborator

iSazonov commented Feb 7, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@iSazonov
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@iSazonov iSazonov self-requested a review April 23, 2025 11:29
@iSazonov
Copy link
Collaborator

iSazonov commented May 8, 2025

@Tadas Please press "Update with rebase" to get latest commits from master branch.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label May 8, 2025
@Tadas Tadas force-pushed the new-item-force-drive-root-fix branch from 63348d3 to 8694def Compare May 8, 2025 14:48
@Tadas
Copy link
Contributor Author

Tadas commented May 8, 2025

@Tadas Please press "Update with rebase" to get latest commits from master branch.

Done

…stem.Tests.ps1

Co-authored-by: Ilya <darpa@yandex.ru>
@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as outdated.

@iSazonov iSazonov changed the title Remove unnecessary path split in FileSystemProvider.CreateDirectory Use absolute path in FileSystemProvider.CreateDirectory May 13, 2025
@iSazonov iSazonov merged commit b3bc4ff into PowerShell:master May 13, 2025
37 checks passed
@microsoft-github-policy-service
Copy link
Contributor

microsoft-github-policy-service bot commented May 13, 2025

📣 Hey @@Tadas, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

@iSazonov
Copy link
Collaborator

@Tadas Thanks for your contribution!

@Tadas
Copy link
Contributor Author

Tadas commented May 13, 2025

Thank you for your help 👍

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.

TestDrive:\ provided to New-Item creates folder in current working directory

2 participants