Browse Source

add an attribute that allows symbolic links to be deleted without following them. PR 36658.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@713641 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
ebac984530
4 changed files with 72 additions and 2 deletions
  1. +5
    -0
      WHATSNEW
  2. +10
    -0
      docs/manual/CoreTasks/delete.html
  3. +34
    -2
      src/main/org/apache/tools/ant/taskdefs/Delete.java
  4. +23
    -0
      src/tests/antunit/taskdefs/delete-and-symlinks-test.xml

+ 5
- 0
WHATSNEW View File

@@ -523,6 +523,11 @@ Other changes:
* a new task <include> provides an alternative to <import> that
should be preferred when you don't want to override any targets.

* delete has a new attribute removeNotFollowedSymlink. If set to
true, symbolic links not followed (because followSymlinks was false
or the number of symlinks was too big) will be removed.
Bugzilla Report 36658.

Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================



+ 10
- 0
docs/manual/CoreTasks/delete.html View File

@@ -154,6 +154,16 @@ in <strong>Directory-based Tasks</strong>, and see the
<em>Since Ant 1.6.2</em></td>
<td align="center" valign="top">No, default &quot;false&quot;</td>
</tr>
<tr>
<td valign="top">removeNotFollowedSymlinks</td>
<td valign="top">
Whether symbolic links (not the files/directories they link to)
should be removed if they haven't been followed because
followSymlinks was false or the maximum number of symbolic links
was too big.
<em>Since Ant 1.8.0</em></td>
<td align="center" valign="top">No, default &quot;false&quot;</td>
</tr>
</table>

<h3>Examples</h3>


+ 34
- 2
src/main/org/apache/tools/ant/taskdefs/Delete.java View File

@@ -26,6 +26,7 @@ import java.util.Comparator;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.PatternSet;
@@ -113,6 +114,7 @@ public class Delete extends MatchingTask {
private boolean quiet = false;
private boolean failonerror = true;
private boolean deleteOnExit = false;
private boolean removeNotFollowedSymlinks = false;
private Resources rcs = null;
private static FileUtils FILE_UTILS = FileUtils.getFileUtils();
private static SymbolicLinkUtils SYMLINK_UTILS =
@@ -337,6 +339,16 @@ public class Delete extends MatchingTask {
super.setFollowSymlinks(followSymlinks);
}

/**
* Sets whether the symbolic links that have not been followed
* shall be removed (the links, not the locations they point at).
*
* @since Ant 1.8.0
*/
public void setRemoveNotFollowedSymlinks(boolean b) {
removeNotFollowedSymlinks = b;
}

/**
* add a "Select" selector entry on the selector list
* @param selector the selector to be added
@@ -592,9 +604,29 @@ public class Delete extends MatchingTask {
handle("Directory does not exist:" + fsDir);
} else {
resourcesToDelete.add(fs);
DirectoryScanner ds = fs.getDirectoryScanner();
if (includeEmpty) {
filesetDirs.add(new ReverseDirs(getProject(), fsDir, fs
.getDirectoryScanner().getIncludedDirectories()));
filesetDirs.add(new ReverseDirs(getProject(), fsDir,
ds
.getIncludedDirectories()));
}

if (removeNotFollowedSymlinks) {
String[] n = ds.getNotFollowedSymlinks();
if (n.length > 0) {
String[] links = new String[n.length];
System.arraycopy(n, 0, links, 0, n.length);
Arrays.sort(links, ReverseDirs.REVERSE);
for (int l = 0; l < links.length; l++) {
try {
SYMLINK_UTILS
.deleteSymbolicLink(new File(links[l]),
this);
} catch (java.io.IOException ex) {
handle(ex);
}
}
}
}
}
}


+ 23
- 0
src/tests/antunit/taskdefs/delete-and-symlinks-test.xml View File

@@ -37,4 +37,27 @@
<symlink link="${link}" resource="${input}/A"/>
<delete dir="${input}"/>
</target>

<target name="testNotFollowedLink" if="unix">
<mkdir dir="${input}/A/B"/>
<mkdir dir="${input}/C"/>
<property name="link" location="${input}/A/B/C"/>
<symlink link="${link}" resource="${input}/C"/>
<delete>
<fileset dir="${input}" followSymlinks="false"/>
</delete>
<au:assertFileExists file="${input}/A/B/C"/>
</target>

<target name="testRemoveNotFollowedLink" if="unix">
<mkdir dir="${input}/A/B"/>
<mkdir dir="${input}/C"/>
<property name="link" location="${input}/A/B/C"/>
<symlink link="${link}" resource="${input}/C"/>
<delete removeNotFollowedSymlinks="true">
<fileset dir="${input}/A" followSymlinks="false"/>
</delete>
<au:assertFileDoesntExist file="${input}/A/B/C"/>
<au:assertFileExists file="${input}/C"/>
</target>
</project>

Loading…
Cancel
Save