加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 使用New-Item创建目录的竞争条件?

发布时间:2020-12-14 04:22:23 所属栏目:Windows 来源:网络整理
导读:我在调用New-Item以使用UNC路径在外部计算机上创建目录时看到了竞争条件.代码如下: New-Item $target -itemType Directory -Force -Verbose | %{ Write-Host "Creating dir" $_.FullName } 之后立即使用Test-Path返回false.我把测试路径 – 睡眠1秒重试循环
我在调用New-Item以使用UNC路径在外部计算机上创建目录时看到了竞争条件.代码如下:
New-Item $target -itemType Directory -Force -Verbose |
        %{ Write-Host "Creating dir" $_.FullName }

之后立即使用Test-Path返回false.我把测试路径 – >睡眠1秒重试循环,睡眠1秒后,Test-Path返回true.

New-Item是阻止通话吗?我应该在打电话给New-Item后等待吗?

我无法重现你的问题.
PS > New-Item "test" -itemType Directory -Force -Verbose | %{ Test-Path $_.FullName }
VERBOSE: Performing the operation "Create Directory" on target "Destination: C:UsersFrodeDesktoptest".
True

New-Item通过获取父目录的DirectoryInfo对象并将其调用为CreateSubDirectory来创建新目录,如:

DirectoryInfo subdirectory = new DirectoryInfo(parentPath).CreateSubdirectory(childName);

我不是开发人员,但AFAIK意味着它是一个阻塞调用,因为它等待一个DirectoryInfo对象作为回报.所以mabe的问题在于您的存储子系统.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读