I'm seeing a race condition when calling New-Item to create a directory on a foreign machine using a UNC path. The code is below:
New-Item $target -itemType Directory -Force -Verbose |
%{ Write-Host "Creating dir" $_.FullName }
Using Test-Path immediately afterwards returns false. I put a Test-Path -> sleep for 1 second retry loop and after sleeping for 1 second, Test-Path is returning true.
Is New-Item a blocking call? Should I expect to have to wait after calling New-Item?
I cannot reproduce your problem.
PS > New-Item "test" -itemType Directory -Force -Verbose | %{ Test-Path $_.FullName }
VERBOSE: Performing the operation "Create Directory" on target "Destination: C:\Users\Frode\Desktop\test".
True
New-Item
creates a new directory by getting a DirectoryInfo-object for the parent directory, and calling it's CreateSubDirectory, like:
DirectoryInfo subdirectory = new DirectoryInfo(parentPath).CreateSubdirectory(childName);
I'm not a developer, but AFAIK that means it's a blocking call, since it waits for an DirectoryInfo
-object in return. So mabe the problem is with your storage subsystem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With