Ant delete first jobs, then don't

I am working on a large Ant script (> 1000 lines) that I inherited from someone else (no longer available). I'm having problems with Ant not deleting directories. At some point in the script it works and at another it doesn't: Ant doesn't give an error message, but it also leaves the directories where they are.

I put groovy around it to check for directories:

  <groovy>
    println("Directories in @{outFolder} are:")
    new File("@{outFolder}").eachDir() { dir -> println dir.getName() }
  </groovy>
  <delete verbose="true" includeEmptyDirs="true" >
    <dirset dir="@{outFolder}" includes="**/*" />
  </delete>
  <echo>End of delete</echo>
  <groovy>
    println("Directories in @{outFolder} are:")
    new File("@{outFolder}").eachDir() { dir -> println dir.getName() }
  </groovy>

      

So the lines get called and they work. Then another application is called, which creates new directories. The exact same lines are called again (copy and paste, and yes they are equal), but now the directories are not deleted. Also: No error, Ant continues to run. I am using Ant 1.8.1 on Windows Server 2008 R2. I tried to add sleep to prevent blocking problems. The application that creates directories is a Java application (Tibco appManage). Directories contain XML files, no jar files. I checked ANT_HOME and CLASSPATH: no problem. What am I missing?

For smart asses: of course, the second delete shouldn't delete everything that was generated by the app, but to fix the problem I made the script lines as simple as possible.

Additional info: Since I can't get to delete the job, I tried using Ant move as a workaround. This is what I see: the move creates empty directories at the destination, does not remove files or directories from the source, and does not report an error. There seems to be something wrong with these original directories / files (which I tried to delete before).

Another try: download the latest Ant and Groovy versions. The same results.

+3


source to share


1 answer


You are using a dirset. Use a set of files.

Explanation: A dirset is not what you think. You almost always want to use a set of files.

The first time it works because the directories are empty. This is not the case the second time. I can say this because it <dirset>

includes the directory objects themselves, but none of the files inside them, and you use "includeEmptyDirs" in your delete task, which doesn't make any sense with dirset.

In a hypothetical tree:



top/
  sub1/
    file.txt
  sub2/ (empty)

      

... the dirset collection will select top /, top / sub1 / and top / sub2 /, but not top / sub1 / file.txt. <delete>

acts on the collection and will not delete non-empty directories. So, in the above case, it will remove the top / sub2 (which is empty) but not top / sub1 or top /. This should also explain to you the results of your attempt <move>

, which gives you some insight into the cases for which dirset can actually be useful.

A fileset contains files and directories.

+4


source







All Articles