A user posted a question about using <delete> with 'includeEmptyDirs' set
(see: http://marc.theaimsgroup.com/?l=ant-user&m=102546976217819&w=2), and
from looking at Delete.java, I don't see it ever handling this -- but the
doc seems to say it can (but maybe I missed how it's supposed to work).
I've modified Delete.java so it does it now, but I had to do some (maybe
kind of weird?) things to get the potentially empty directories from the
fileset into the "dirs" array -- which is set by a call to
getIncludedDirectories() (which is why I had to do the maybe weird stuff,
to get an already set array to "grow" to include the other dir names),
except the call to getIncludedDirectories() doesn't actually return any
names (which is why the code that's supposed to delete the now-empty
directories never gets executed), and I'm not really sure if that's
expected or not (if it's not, then I've probably made the wrong fix, and
what needs to get fixed instead is getting the names of the file's
directories into "dirs" from the start).
Since this isn't exactly what you'd call a real straightforward change
(although it's actually fairly small, despite the convoluted description
:), I'd really appreciate it if some of the other committers take a look
at it before I submit it. I've done my usual test-by-hand thing, and it
seems to work fine -- but of course, you'll want real testcases stuff as
well, right? (Ugh.)
Diane
=====
([EMAIL PROTECTED])
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
Index: Delete.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Delete.java,v
retrieving revision 1.31.2.1
diff -b -u -r1.31.2.1 Delete.java
--- Delete.java 19 Jun 2002 01:22:12 -0000 1.31.2.1
+++ Delete.java 1 Jul 2002 05:04:24 -0000
@@ -415,6 +415,7 @@
*/
protected void removeFiles(File d, String[] files, String[] dirs) {
if (files.length > 0) {
+ Vector vdirs = new Vector(); // capture names of directories
log("Deleting " + files.length + " files from "
+ d.getAbsolutePath());
for (int j = 0; j < files.length; j++) {
@@ -430,13 +431,40 @@
quiet ? Project.MSG_VERBOSE : Project.MSG_WARN);
}
}
+ // List of potential empty directories
+ if (includeEmpty) {
+ File emptyDir = new File(f.getParent());
+ vdirs.add(emptyDir.toString());
+ }
+ }
+ if (includeEmpty && vdirs.size() > 0) {
+ // Get the list into an array
+ Object[] entries = new Object[0];
+ entries = vdirs.toArray(entries);
+ String[] dirNames = new String[dirs.length + entries.length];
+ String[] er = new String[entries.length];
+
+ // Reverse the order, so we can do bottom-most first
+ int i = 0 ;
+ for (int j = entries.length - 1; j >= 0; j--) {
+ er[i] = (String)entries[j];
+ i++;
+ }
+
+ // Get the new data into the dirs directory
+ System.arraycopy(dirs,0,dirNames,0,dirs.length);
+ System.arraycopy(er,0,dirNames,dirs.length,er.length);
+ dirs = (String[])dirNames;
}
}
if (dirs.length > 0 && includeEmpty) {
int dirCount = 0;
for (int j = dirs.length - 1; j >= 0; j--) {
- File dir = new File(d, dirs[j]);
+ File dir = new File(dirs[j]);
+ if (!dir.isAbsolute()) {
+ dir = new File(d, dirs[j]);
+ }
String[] dirFiles = dir.list();
if (dirFiles == null || dirFiles.length == 0) {
log("Deleting " + dir.getAbsolutePath(), verbosity);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>