You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Andrew Clegg <an...@gmail.com> on 2008/06/23 18:29:10 UTC

Issues with delete -- manual and FAQ incorrect (?)

Hi everyone,

I'm having problems setting a task to delete everything in a
particular directory. But wait, before you say "this is a FAQ", I've
tested the solution given in the manual and FAQ, and it doesn't
actually work.

My task looks like this, as per standard instructions (autosrc is a
tree of source code generated by Axis2):

	<target name="codegen.clean">
		<delete verbose="true" includeEmptyDirs="true">
			<fileset dir="autosrc" includes="**/*"/>
		</delete>
  	</target>

Below is a direct cut-and-paste from my terminal window when I run it
twice, with an ls before, between and after. You'll notice that the
first time it runs, it recursively removes all the FILES from the
autosrc directory, but not the empty directories, despite the
includeemptydirs="true". Fair enough, I thought, perhaps they don't
count as empty unless they're empty when the task is invoked. But,
look at the second run -- this time it does nothing at all.


17:20:52 0 jobs clegg@bsmlx47 ~/data/GanymedeWorkspace/cathws
(394) bash $ ls autosrc
info  org

17:22:05 0 jobs clegg@bsmlx47 ~/data/GanymedeWorkspace/cathws
(395) bash $ AXIS2_HOME=axis2-1.3/ ant -v codegen.clean
Apache Ant version 1.6.5 compiled on January 6 2007
Buildfile: build.xml
Detected Java version: 1.5 in: /export/people/clegg/java/jdk/jre
Detected OS: Linux
parsing buildfile
/export/people/clegg/data/GanymedeWorkspace/cathws/build.xml with URI
= file:///export/people/clegg/data/GanymedeWorkspace/cathws/build.xml
Project base dir set to: /export/people/clegg/data/GanymedeWorkspace/cathws
 [property] Loading Environment env.
Build sequence for target(s) `codegen.clean' is [codegen.clean]
Complete build sequence is [codegen.clean, init, jar.xbeans,
pre.compile.test, compile.src, echo.classpath.problem, jar.server,
make.repo, codegen, jar.client, jar.all, compile.test, run.test,
clean, start.server, ]

codegen.clean:
   [delete] Deleting 327 files from
/export/people/clegg/data/GanymedeWorkspace/cathws/autosrc
   [delete] Deleting
/export/people/clegg/data/GanymedeWorkspace/cathws/autosrc/info/cathdb/ws/grid/MonitorMessageReceiverInOut.java
   [delete] Deleting
/export/people/clegg/data/GanymedeWorkspace/cathws/autosrc/info/cathdb/ws/grid/MonitorSkeleton.java
   [delete] Deleting
/export/people/clegg/data/GanymedeWorkspace/cathws/autosrc/info/cathdb/ws/grid/MonitorSkeletonInterface.java
[MANY SIMILAR LINES SNIPPED]
   [delete] Deleting
/export/people/clegg/data/GanymedeWorkspace/cathws/autosrc/org/xmlsoap/schemas/soap/encoding/impl/UnsignedShortDocumentImpl.java
   [delete] Deleting
/export/people/clegg/data/GanymedeWorkspace/cathws/autosrc/org/xmlsoap/schemas/soap/encoding/impl/UnsignedShortImpl.java

BUILD SUCCESSFUL
Total time: 0 seconds

17:22:09 0 jobs clegg@bsmlx47 ~/data/GanymedeWorkspace/cathws
(396) bash $ ls autosrc
info  org

17:22:11 0 jobs clegg@bsmlx47 ~/data/GanymedeWorkspace/cathws
(397) bash $ AXIS2_HOME=axis2-1.3/ ant -v codegen.clean
Apache Ant version 1.6.5 compiled on January 6 2007
Buildfile: build.xml
Detected Java version: 1.5 in: /export/people/clegg/java/jdk/jre
Detected OS: Linux
parsing buildfile
/export/people/clegg/data/GanymedeWorkspace/cathws/build.xml with URI
= file:///export/people/clegg/data/GanymedeWorkspace/cathws/build.xml
Project base dir set to: /export/people/clegg/data/GanymedeWorkspace/cathws
 [property] Loading Environment env.
Build sequence for target(s) `codegen.clean' is [codegen.clean]
Complete build sequence is [codegen.clean, init, jar.xbeans,
pre.compile.test, compile.src, echo.classpath.problem, jar.server,
make.repo, codegen, jar.client, jar.all, compile.test, run.test,
clean, start.server, ]

codegen.clean:

BUILD SUCCESSFUL
Total time: 0 seconds

17:22:13 0 jobs clegg@bsmlx47 ~/data/GanymedeWorkspace/cathws
(398) bash $ ls autosrc
info  org


I've seen a lot of questions about this topic on the web that just
repeat the instructions from the manual, but they just don't work as
described. It doesn't remove the empty directories no matter how many
times I run it.

Any ideas? Please don't say "just delete the directory and re-create
it" because then it becomes disconnected from Subversion, and I want
to maintain version history on auto-generated code just as much as I
want it on normal code. And besides, that answer doesn't address the
fact that a manual page and FAQ both appear to be wrong...

Thanks,

Andrew.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Issues with delete -- manual and FAQ incorrect (?)

Posted by Andrew Clegg <an...@gmail.com>.
2008/6/24 Stefan Bodewig <bo...@apache.org>:

> In most cases Ant's behavior probably is exactly what is intended by
> many people.  You don't want to lose your real work when removing
> backups recursively (deleting the directories that don't contain any
> backups because no file matched the include pattern).

Yes, true.

> I'll update the manual.

Nice one, and thanks for your help!

Andrew.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Issues with delete -- manual and FAQ incorrect (?)

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 24 Jun 2008, Andrew Clegg <an...@gmail.com> wrote:

> I have just had a couple of thoughts which I'll post here for the
> benefit of others who might be in a similar situation.
> 
> I think my original problem is because each of the subdirectories in
> the autosrc tree contains an ignored .svn directory, meaning that
> none of them are ever completely empty, so they don't get removed.
> 
> Perhaps this also explains why
> 
>                <delete verbose="true" includeemptydirs="true">
>                        <fileset dir="autosrc"/>
>                </delete>
> 
> leaves the autosrc directory, when the manual suggests it should
> remove it. There's still a .svn file in there which protects it from
> deletion.

I think you are correct.

> However there is perhaps a small inconsistency in the fact that Ant
> ignores .svn directories (and various others) when deciding what to
> delete, but doesn't ignore them when deciding if a directory is
> empty.

In most cases Ant's behavior probably is exactly what is intended by
many people.  You don't want to lose your real work when removing
backups recursively (deleting the directories that don't contain any
backups because no file matched the include pattern).

When deciding whether a directory is empty, Ant asks the OS and
doesn't only consult its internal list of files that matched the
include pattern(s).

I'll update the manual.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Issues with delete -- manual and FAQ incorrect (?)

Posted by Andrew Clegg <an...@gmail.com>.
I have just had a couple of thoughts which I'll post here for the
benefit of others who might be in a similar situation.

I think my original problem is because each of the subdirectories in
the autosrc tree contains an ignored .svn directory, meaning that none
of them are ever completely empty, so they don't get removed.

Perhaps this also explains why

               <delete verbose="true" includeemptydirs="true">
                       <fileset dir="autosrc"/>
               </delete>

leaves the autosrc directory, when the manual suggests it should
remove it. There's still a .svn file in there which protects it from
deletion.

I can't explain why the above target removed *everything* in that
autosrc tree when I tried it earlier this morning though -- perhaps I
had changed something else without realising it -- because running it
again now seems to have had the same effect as running it with the
include filter yesterday (i.e. leaving the directory tree intact).

So I don't think this is a bug after all. Indeed from my point of view
it's probably better not to delete the empty autosrc tree, and
recreate it when I re-run my code generation task, as this disconnects
the tree from subversion in an irritating way. However there is
perhaps a small inconsistency in the fact that Ant ignores .svn
directories (and various others) when deciding what to delete, but
doesn't ignore them when deciding if a directory is empty. I think
this was the root of my confusion, maybe it should be highlighted in
the manual?

Cheers,

Andrew.

2008/6/24 Andrew Clegg <an...@gmail.com>:
> 2008/6/24 Stefan Bodewig <bo...@apache.org>:
>
>> I don't think your directories info and src match the includes pattern
>> **/* which means "at least one directory level deeper than base".
>> What happens if you remove the includes attribute completely?
>
> That works! Thanks. But this means the manual is definitely wrong.
>
> From http://ant.apache.org/manual/CoreTasks/delete.html ...
>
>
>  <delete includeEmptyDirs="true">
>    <fileset dir="build"/>
>  </delete>
>
> deletes all files and subdirectories of build, including build itself.
>
>  <delete includeemptydirs="true">
>    <fileset dir="build" includes="**/*"/>
>  </delete>
>
> deletes all files and subdirectories of build, without build itself.
>
>
> However my target looks like this:
>
>
>        <target name="codegen.clean">
>                <delete verbose="true" includeemptydirs="true">
>                        <fileset dir="autosrc"/>
>                </delete>
>        </target>
>
>
> and it has just deleted everything inside my autosrc directory
> (except, correctly, .svn which is in the default excludes) but left
> autosrc itself intact.
>
>
> 09:24:00 0 jobs clegg@bsmlx47 ~/data/GanymedeWorkspace/cathws
> (436) bash $ ls -la autosrc/
> total 12
> drwxr-xr-x 3 clegg users 4096 Jun 24 09:23 .
> drwxr-xr-x 9 clegg users 4096 Jun 23 15:55 ..
> drwxr-xr-x 6 clegg users 4096 Jun 23 15:55 .svn
>
>
> Should I submit this as a bug report somewhere? I'm running Ant 1.6.5
> in Sun Java 1.6.0_06-b02 on Centos 5 (i.e. basically RedHat
> Enterprise).
>
> Thanks,
>
> Andrew.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Issues with delete -- manual and FAQ incorrect (?)

Posted by Andrew Clegg <an...@gmail.com>.
2008/6/24 Stefan Bodewig <bo...@apache.org>:

> I don't think your directories info and src match the includes pattern
> **/* which means "at least one directory level deeper than base".
> What happens if you remove the includes attribute completely?

That works! Thanks. But this means the manual is definitely wrong.

>From http://ant.apache.org/manual/CoreTasks/delete.html ...


  <delete includeEmptyDirs="true">
    <fileset dir="build"/>
  </delete>

deletes all files and subdirectories of build, including build itself.

  <delete includeemptydirs="true">
    <fileset dir="build" includes="**/*"/>
  </delete>

deletes all files and subdirectories of build, without build itself.


However my target looks like this:


	<target name="codegen.clean">
		<delete verbose="true" includeemptydirs="true">
			<fileset dir="autosrc"/>
		</delete>
  	</target>


and it has just deleted everything inside my autosrc directory
(except, correctly, .svn which is in the default excludes) but left
autosrc itself intact.


09:24:00 0 jobs clegg@bsmlx47 ~/data/GanymedeWorkspace/cathws
(436) bash $ ls -la autosrc/
total 12
drwxr-xr-x 3 clegg users 4096 Jun 24 09:23 .
drwxr-xr-x 9 clegg users 4096 Jun 23 15:55 ..
drwxr-xr-x 6 clegg users 4096 Jun 23 15:55 .svn


Should I submit this as a bug report somewhere? I'm running Ant 1.6.5
in Sun Java 1.6.0_06-b02 on Centos 5 (i.e. basically RedHat
Enterprise).

Thanks,

Andrew.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Issues with delete -- manual and FAQ incorrect (?)

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 23 Jun 2008, Andrew Clegg <an...@gmail.com> wrote:

> Hi everyone,
> 
> I'm having problems setting a task to delete everything in a
> particular directory. But wait, before you say "this is a FAQ", I've
> tested the solution given in the manual and FAQ, and it doesn't
> actually work.
> 
> My task looks like this, as per standard instructions (autosrc is a
> tree of source code generated by Axis2):
> 
> 	<target name="codegen.clean">
> 		<delete verbose="true" includeEmptyDirs="true">
> 			<fileset dir="autosrc" includes="**/*"/>
> 		</delete>
>   	</target>
> 
> Below is a direct cut-and-paste from my terminal window when I run
> it twice, with an ls before, between and after.

<snip/>

> 17:20:52 0 jobs clegg@bsmlx47 ~/data/GanymedeWorkspace/cathws
> (394) bash $ ls autosrc
> info  org

I don't think your directories info and src match the includes pattern
**/* which means "at least one directory level deeper than base".
What happens if you remove the includes attribute completely?

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org