Bug 63956 - <delete> with followSymlinks="false" fails to delete directory
Summary: <delete> with followSymlinks="false" fails to delete directory
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.10.5
Hardware: Macintosh All
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-22 21:51 UTC by Archie Cobbs
Modified: 2019-12-27 19:34 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Archie Cobbs 2019-11-22 21:51:03 UTC
$ ant -version
Apache Ant(TM) version 1.10.5 compiled on July 10 2018

This task simply does not work:

    <delete dir="somedir" followSymlinks="false"/>

Example:

When I run "ant" with this "build.xml":

  <project name="ant-bug" default="test">
    <target name="test">
        <echo message="creating somedir..."/>
        <mkdir dir="somedir"/>
        <echo message="showing somedir (it should be there)..."/>
        <exec executable="/bin/ls" logError="true" failonerror="true">
            <arg value="-ld"/>
            <arg value="somedir"/>
        </exec>
        <echo message="deleting somedir..."/>
        <delete dir="somedir" followSymlinks="false"/>
        <echo message="showing somedir (it should NOT be there)..."/>
        <exec executable="/bin/ls" logError="true" failonerror="true">
            <arg value="-ld"/>
            <arg value="somedir"/>
        </exec>
    </target>
  </project>

I get this output:

Buildfile: /Users/archie/Downloads/ant-bug/build.xml

test:
     [echo] creating somedir...
    [mkdir] Created dir: /Users/archie/Downloads/ant-bug/somedir
     [echo] showing somedir (it should be there)...
     [exec] drwxr-xr-x  2 archie  staff  64 Nov 22 15:50 somedir
     [echo] deleting somedir...
     [echo] showing somedir (it should NOT be there)...
     [exec] drwxr-xr-x  2 archie  staff  64 Nov 22 15:50 somedir

BUILD SUCCESSFUL
Total time: 0 seconds
Comment 1 Gintas Grigelionis 2019-12-27 19:34:03 UTC
The task works, but "dir" attribute gets a special treatment for the reasons that are not (fully) documented. If you look at the source code [1], setting almost any other attribute makes the task to ignore "dir". In this particular case, "dir" is ignored whenever "followSymlinks" is set explicitly, either to "true" or "false". Nonetheless, the task should emit a warning when doing so.

[1] https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/taskdefs/Delete.java#L629