ASF Bugzilla – Attachment 16406 Details for
Bug 36658
Delete task follows symlinks - bad behavior
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
delete dir [do not] follow symlinks patch
patch.txt (text/plain), 4.05 KB, created by
Jens Elkner
on 2005-09-14 18:45:37 UTC
(
hide
)
Description:
delete dir [do not] follow symlinks patch
Filename:
MIME Type:
Creator:
Jens Elkner
Created:
2005-09-14 18:45:37 UTC
Size:
4.05 KB
patch
obsolete
>Index: Delete.java >=================================================================== >--- src/main/org/apache/tools/ant/taskdefs/Delete.java (revision 280547) >+++ src/main/org/apache/tools/ant/taskdefs/Delete.java (working copy) >@@ -18,6 +18,7 @@ > package org.apache.tools.ant.taskdefs; > > import java.io.File; >+import java.io.IOException; > import java.util.Vector; > import org.apache.tools.ant.BuildException; > import org.apache.tools.ant.DirectoryScanner; >@@ -70,7 +71,8 @@ > private boolean quiet = false; > private boolean failonerror = true; > private boolean deleteOnExit = false; >- >+ private boolean followSymlinks = false; >+ > /** > * Set the name of a single file to be removed. > * >@@ -146,7 +148,7 @@ > public void setIncludeEmptyDirs(boolean includeEmpty) { > this.includeEmpty = includeEmpty; > } >- >+ > /** > * Adds a set of files to be deleted. > * @param set the set of files to be deleted >@@ -273,8 +275,11 @@ > * @param followSymlinks whether or not symbolic links should be followed > */ > public void setFollowSymlinks(boolean followSymlinks) { >- usedMatchingTask = true; >+ // usedMatchingTask = true; > super.setFollowSymlinks(followSymlinks); >+ // since we do not have access to fileset.followSymlinks - used in >+ // #removeDir(dir) >+ this.followSymlinks = followSymlinks; > } > > /** >@@ -576,29 +581,41 @@ > * @param d the directory to delete > */ > protected void removeDir(File d) { >- String[] list = d.list(); >- if (list == null) { >- list = new String[0]; >- } >- for (int i = 0; i < list.length; i++) { >- String s = list[i]; >- File f = new File(d, s); >- if (f.isDirectory()) { >- removeDir(f); >- } else { >- log("Deleting " + f.getAbsolutePath(), verbosity); >- if (!delete(f)) { >- String message = "Unable to delete file " >- + f.getAbsolutePath(); >- if (failonerror) { >- throw new BuildException(message); >- } else { >- log(message, >- quiet ? Project.MSG_VERBOSE : Project.MSG_WARN); >- } >- } >- } >- } >+ boolean assumeRealDir = true; >+ if (!followSymlinks) { // fileset is always none-null >+ String path = d.getAbsolutePath(); >+ String realPath = null; >+ try { >+ realPath = d.getCanonicalPath(); >+ } catch (IOException ioe) { >+ // link to nowhere >+ } >+ assumeRealDir = (realPath != null) && path.equals(realPath); >+ } >+ if (assumeRealDir) { >+ String[] list = d.list(); >+ if (list == null) { >+ list = new String[0]; >+ } >+ for (int i = 0; i < list.length; i++) { >+ String s = list[i]; >+ File f = new File(d, s); >+ if (f.isDirectory()) { >+ removeDir(f); >+ } else { >+ log("Deleting " + f.getAbsolutePath(), verbosity); >+ if (!delete(f)) { >+ String message = "Unable to delete file " >+ + f.getAbsolutePath(); >+ if (failonerror) { >+ throw new BuildException(message); >+ } >+ log(message, >+ quiet ? Project.MSG_VERBOSE : Project.MSG_WARN); >+ } >+ } >+ } >+ } > log("Deleting directory " + d.getAbsolutePath(), verbosity); > if (!delete(d)) { > String message = "Unable to delete directory " >@@ -605,10 +622,8 @@ > + dir.getAbsolutePath(); > if (failonerror) { > throw new BuildException(message); >- } else { >- log(message, >- quiet ? Project.MSG_VERBOSE : Project.MSG_WARN); > } >+ log(message, quiet ? Project.MSG_VERBOSE : Project.MSG_WARN); > } > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 36658
: 16406