Bug 23789

Summary: warn if <delete task contains a fileset AND a dir attribute!! The content of dir is deleted before fileset's exclude is evaluated!!!
Product: Ant Reporter: Ralf Hauser <hauser>
Component: CoreAssignee: Ant Notifications List <notifications>
Status: NEW ---    
Severity: enhancement    
Priority: P3    
Version: 1.6.0   
Target Milestone: ---   
Hardware: Other   
OS: other   
URL: http://ant.apache.org/manual/CoreTasks/delete.html

Description Ralf Hauser 2003-10-13 17:02:43 UTC
I had a simple delete task
<delete dir="${build.dir}" includeEmptyDirs="true" />
and wanted to exclude something
  excludes="**/transform/**/*.* ${ASM_jar}"
Doing that I got the DEPRECATED error and added
  <fileset dir="${build.dir}">
    <exclude name="**/transform/*.class" />
    <include name="**/*.*" />
  </fileset>
resulting in
<delete dir="${build.dir}" includeEmptyDirs="true">
  <fileset dir="${build.dir}">
    <exclude name="**/transform/*.class" />
    <include name="**/*.*" />
  </fileset>
</delete>

BUILD FAILED
file:build.xml:667: WEB-INF/classes not found.

The exclude statement came too late and all its contents were already gone!

Suggested resolution:
if a nested fileset is present, warn about deleting what is specified in "dir"
Comment 1 Stefan Bodewig 2003-10-14 08:15:48 UTC
It is perfectly legal to use both the attribute and nested filesets, a warning may
even be annoying for users that do so on purpose.
Comment 2 Ralf Hauser 2003-10-14 09:00:24 UTC
under the "fail-safe" principle, how about warning anyway and have for this
delicate task "delete" a *expert* flag that suppresses the warnings!
Comment 3 Gus Heck 2003-10-15 16:09:08 UTC
From the manual entry for the dir atribute:

The directory to delete, including all its files and subdirectories.
Note: dir is not used to specify a directory name for file; file and dir are
independent of each other.
WARNING: Do not set dir to ".", "${basedir}", or the full-pathname equivalent
unless you truly intend to recursively remove the entire contents of the current
base directory (and the base directory itself, if different from the current
working directory).

Granted, it doesn't say that dir is independant of the filesets, but since
filesets have their own dir atribute it isn't that supprising. I'd say perhaps
clarify in the manual at most. But I think the current entry is fairly clear, so
maybe not even that.