ant 中的 mkdir 失败.我该如何处理这个错误 [英] mkdir in ant fails. How can i handle this error

查看:34
本文介绍了ant 中的 mkdir 失败.我该如何处理这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有的 ANT 构建脚本执行以下操作:

The ANT build script I have does the following:

  1. 在 Windows 服务器上执行构建 &压缩二进制文件
  2. 使用 net use
  3. 将具有不同凭据的网络驱动器映射到本地驱动器(例如 P:)
  4. 我正在使用 在挂载的驱动器 (P:) 上创建一个目录
  5. 将二进制文件复制到该驱动器
  1. Perform the builds on Windows server & Zip the binaries
  2. Map a network drive with different credentials to a local drive (ex P:) using net use
  3. I am using <mkdir> to create a directory on the mounted drive (P:)
  4. Copy the binaries to that drive

下面是我的 mkdir

<echo>Creating ${buildRequesterUserId} folder at mirroring site starts</echo>
<mkdir dir="P:\build_output\${buildRequesterUserId}"/>
<echo>Creating ${buildRequesterUserId} folder at mirroring site ends</echo>

有时创建文件夹有效,有时失败并显示以下错误

Some time the creation of folder works and some time it fails with below error

由于未知原因创建未成功并导致构建失败

这个错误是随机发生的.Mkdir 工作了一段时间.我不确定它为什么会失败,也不确定是不是因为网络延迟

This error happens randomly. The Mkdir works some time. I am not sure why it fails and not sure if its because of network lag

我尝试创建的目录也可能已经存在,也可能不存在.我读到如果目录已经存在,则 mkdir 不会做任何事情

also the directory i am trying to create may or may not exist already. I read that the mkdir does not do anything if directory exists already

我检查过,mkdir 没有 failonerror.我不希望构建因此而失败.

I checked and there is no failonerror for mkdir. I don't want the build to fail because of this.

我已经处理了 copy 部分的错误,但不确定如何处理这个 mkdir

I have handled the error in copy part but not sure how to handle this mkdir

我怎样才能做到这一点?任何帮助将不胜感激

How can I achieve this? Any help would be appreciated

问候

卡西克

推荐答案

Apache Ant Mkdir 任务正在调用 File.mkdirs() 方法,它是 易受竞争条件的影响.

Apache Ant Mkdir task is calling File.mkdirs() method which is vulnerable to race conditions.

File.mkdirs() 不是原子操作 - 我猜它是作为一系列 mkdir 调用实现的.

File.mkdirs() is not an atomic operation - I guess it is implemented as a sequence of mkdir calls.

在远程文件系统的情况下,您的主机很有可能在 File.mkdirs() 操作过程中意识到文件系统更改并且失败.

In case of a remote filsystem there's a good chance that your host gets aware of filesystem changes in the middle of File.mkdirs() operation and it fails.

Ant 似乎试图修复它,因为 Mkdir 代码从 1.8.0

Ant seemed to try to fix it as Mkdir code changed from this in 1.8.0

boolean result = mkdirs(dir);
if (!result) {
  String msg = "Directory " + dir.getAbsolutePath()
         + " creation was not successful for an unknown reason";
  throw new BuildException(msg, getLocation());
}

1.8.2

boolean result = mkdirs(dir);
if (!result) {
  if (dir.exists()) {
    log("A different process or task has already created "
         + "dir " + dir.getAbsolutePath(),
         Project.MSG_VERBOSE);
    return;
  }
  String msg = "Directory " + dir.getAbsolutePath()
         + " creation was not successful for an unknown reason";
  throw new BuildException(msg, getLocation());
}

那么也许升级到最新的 Ant 会有所帮助?

so maybe upgrading to the latest Ant could help?

如果没有 - 可以使用您自己的 execute() 方法实现创建一些蛮力 Mkdir 任务扩展.

If not - some brute force Mkdir task extension could be created with your own execute() method implementation.

如果没有 - 来自 Ant Contrib 的 Trycatch 任务 将起作用.

If not - Trycatch task from Ant Contrib will work.

这篇关于ant 中的 mkdir 失败.我该如何处理这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆