Browse Source

Don't remove basedirectories of <fileset>s that just happen to be

matched completely.
PR: 18886


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274592 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
c9f232a4f9
2 changed files with 2 additions and 66 deletions
  1. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  2. +0
    -65
      src/main/org/apache/tools/ant/taskdefs/Move.java

+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -391,7 +391,8 @@ public class Copy extends Task {

String[] srcFiles = ds.getIncludedFiles();
String[] srcDirs = ds.getIncludedDirectories();
boolean isEverythingIncluded = ds.isEverythingIncluded();
boolean isEverythingIncluded = ds.isEverythingIncluded()
&& (!fs.hasSelectors() && !fs.hasPatterns());
if (isEverythingIncluded
&& !flatten && mapperElement == null) {
completeDirMap.put(fromDir, destDir);


+ 0
- 65
src/main/org/apache/tools/ant/taskdefs/Move.java View File

@@ -213,71 +213,6 @@ public class Move extends Copy {
+ destDir.getAbsolutePath());
}
}

if (filesets.size() > 0) {
Enumeration e = filesets.elements();
while (e.hasMoreElements()) {
FileSet fs = (FileSet) e.nextElement();
File dir = fs.getDir(getProject());

if (okToDelete(dir)) {
deleteDir(dir);
}
}
}
}

/**
* Its only ok to delete a directory tree if there are
* no files in it.
* @return true if a deletion can go ahead
*/
protected boolean okToDelete(File d) {
String[] list = d.list();
if (list == null) {
return false;
} // maybe io error?

for (int i = 0; i < list.length; i++) {
String s = list[i];
File f = new File(d, s);
if (f.isDirectory()) {
if (!okToDelete(f)) {
return false;
}
} else {
return false; // found a file
}
}

return true;
}

/**
* Go and delete the directory tree.
*/
protected void deleteDir(File d) {
String[] list = d.list();
if (list == null) {
return;
} // on an io error list() can return null

for (int i = 0; i < list.length; i++) {
String s = list[i];
File f = new File(d, s);
if (f.isDirectory()) {
deleteDir(f);
} else {
throw new BuildException("UNEXPECTED ERROR - The file "
+ f.getAbsolutePath()
+ " should not exist!");
}
}
log("Deleting directory " + d.getAbsolutePath(), verbosity);
if (!d.delete()) {
throw new BuildException("Unable to delete directory "
+ d.getAbsolutePath());
}
}

/**


Loading…
Cancel
Save