MKDIR蚂蚁失败。我该如何处理此错误 [英] mkdir in ant fails. How can i handle this error

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

问题描述

Ant构建脚本我有执行以下操作:


  1. 执行版本的Windows服务器和放大器上;邮编二进制文件

  2. 地图用不同的凭据到本地驱动器网络驱动器(例如P :)使用 NET USE

  3. 我使用<&的mkdir GT; 以创建安装的驱动器的目录(P :)

  4. 二进制文件复制到硬盘

下面是我的code为的mkdir

 <回声>创建$ {} buildRequesterUserId在镜像站点文件夹开始< /回声>
< MKDIR DIR =P:\\ build_output \\ $ {} buildRequesterUserId/>
<回声>创建$ {} buildRequesterUserId在镜像站点文件夹结束< /回声>

一段时间创作的文件夹的作品,有些时候它失败,提示以下错误:

创建不成功,原因未知,使构建失败

此错误发生随机。该MKDIR工作一段时间。我不知道失败的原因,并不能确定其是否由于网络滞后

另外,我想创建可能会或可能不存在的目录。我读,如果目录已经存在的mkdir没有做任何事情。

我查了一下,也没有 failonerror 为的mkdir。我不想因为这个构建失败。

我已经处理了错误复制部分,但不知道如何处理这种的mkdir

我怎样才能做到这一点?任何帮助将是AP preciated

问候

KARTHIK


解决方案

Apache Ant的 MKDIR 任务调用 File.mkdirs()方法,它是脆弱的竞争条件

File.mkdirs()不是一个原子操作 - 我想这是作为的mkdir 的序列呼叫。

在远程filsystem的情况下,有一个很好的机会,你的主机会感知的中间File.mkdirs()运行文件系统的变化和它失败。

蚂蚁似乎要修复它为 MKDIR code从此在<一个改变href=\"http://javasource$c$c.org/html/open-source/ant/ant-1.8.0/org/apache/tools/ant/taskdefs/Mkdir.java.html\"相对=nofollow> 1.8.0

 布尔结果= mkdirs(DIR);
如果(!结果){
  弦乐味精=目录+ dir.getAbsolutePath()
         +的创作是没有成功,原因未知;
  抛出新BuildException(味精,的getLocation());
}

要在此<一个href=\"http://javasource$c$c.org/html/open-source/ant/ant-1.8.2/org/apache/tools/ant/taskdefs/Mkdir.java.html\"相对=nofollow> 1.8.2

 布尔结果= mkdirs(DIR);
如果(!结果){
  如果(dir.exists()){
    日志(一个不同的过程或任务已经创建了
         +DIR+ dir.getAbsolutePath()
         Project.MSG_VERBOSE);
    返回;
  }
  弦乐味精=目录+ dir.getAbsolutePath()
         +的创作是没有成功,原因未知;
  抛出新BuildException(味精,的getLocation());
}

所以也许升级到最新的蚂蚁可以帮助?

如果没有 - 有些蛮力 MKDIR 任务扩展可以用自己创建的execute()方法实现。

如果没有 - 从蚂蚁的Contrib Trycatch任务将工作<。 / p>

The ANT build script I have does the following:

  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

Below is my code for 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

creation was not successful for an unknown reason and makes the build fail

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

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

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

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

Regards

Karthik

解决方案

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

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

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 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());
}

to this in 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());
}

so maybe upgrading to the latest Ant could help?

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

If not - Trycatch task from Ant Contrib will work.

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

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