View | Details | Raw Unified | Return to bug 36658
Collapse All | Expand All

(-)src/main/org/apache/tools/ant/taskdefs/Delete.java (-29 / +44 lines)
Lines 18-23 Link Here
18
package org.apache.tools.ant.taskdefs;
18
package org.apache.tools.ant.taskdefs;
19
19
20
import java.io.File;
20
import java.io.File;
21
import java.io.IOException;
21
import java.util.Vector;
22
import java.util.Vector;
22
import org.apache.tools.ant.BuildException;
23
import org.apache.tools.ant.BuildException;
23
import org.apache.tools.ant.DirectoryScanner;
24
import org.apache.tools.ant.DirectoryScanner;
Lines 70-76 Link Here
70
    private boolean quiet = false;
71
    private boolean quiet = false;
71
    private boolean failonerror = true;
72
    private boolean failonerror = true;
72
    private boolean deleteOnExit = false;
73
    private boolean deleteOnExit = false;
73
74
    private boolean followSymlinks = false;
75
    
74
    /**
76
    /**
75
     * Set the name of a single file to be removed.
77
     * Set the name of a single file to be removed.
76
     *
78
     *
Lines 146-152 Link Here
146
    public void setIncludeEmptyDirs(boolean includeEmpty) {
148
    public void setIncludeEmptyDirs(boolean includeEmpty) {
147
        this.includeEmpty = includeEmpty;
149
        this.includeEmpty = includeEmpty;
148
    }
150
    }
149
151
    
150
   /**
152
   /**
151
    * Adds a set of files to be deleted.
153
    * Adds a set of files to be deleted.
152
    * @param set the set of files to be deleted
154
    * @param set the set of files to be deleted
Lines 273-280 Link Here
273
     * @param followSymlinks whether or not symbolic links should be followed
275
     * @param followSymlinks whether or not symbolic links should be followed
274
     */
276
     */
275
    public void setFollowSymlinks(boolean followSymlinks) {
277
    public void setFollowSymlinks(boolean followSymlinks) {
276
        usedMatchingTask = true;
278
    	// usedMatchingTask = true;
277
        super.setFollowSymlinks(followSymlinks);
279
        super.setFollowSymlinks(followSymlinks);
280
        // since we do not have access to fileset.followSymlinks - used in
281
        // #removeDir(dir)
282
        this.followSymlinks = followSymlinks; 
278
    }
283
    }
279
284
280
    /**
285
    /**
Lines 576-604 Link Here
576
     * @param d the directory to delete
581
     * @param d the directory to delete
577
     */
582
     */
578
    protected void removeDir(File d) {
583
    protected void removeDir(File d) {
579
        String[] list = d.list();
584
    	boolean assumeRealDir = true;
580
        if (list == null) {
585
    	if (!followSymlinks) { // fileset is always none-null
581
            list = new String[0];
586
    		String path = d.getAbsolutePath();
582
        }
587
    		String realPath = null;
583
        for (int i = 0; i < list.length; i++) {
588
    		try {
584
            String s = list[i];
589
    			realPath = d.getCanonicalPath();
585
            File f = new File(d, s);
590
    		} catch (IOException ioe) {
586
            if (f.isDirectory()) {
591
    			// link to nowhere
587
                removeDir(f);
592
    		}
588
            } else {
593
    		assumeRealDir = (realPath != null) && path.equals(realPath);
589
                log("Deleting " + f.getAbsolutePath(), verbosity);
594
    	}
590
                if (!delete(f)) {
595
    	if (assumeRealDir) {
591
                    String message = "Unable to delete file "
596
	        String[] list = d.list();
592
                        + f.getAbsolutePath();
597
	        if (list == null) {
593
                    if (failonerror) {
598
	            list = new String[0];
594
                        throw new BuildException(message);
599
	        }
595
                    } else {
600
	        for (int i = 0; i < list.length; i++) {
596
                        log(message,
601
	            String s = list[i];
597
                            quiet ? Project.MSG_VERBOSE : Project.MSG_WARN);
602
	            File f = new File(d, s);
598
                    }
603
	            if (f.isDirectory()) {
599
                }
604
	                removeDir(f);
600
            }
605
	            } else {
601
        }
606
	                log("Deleting " + f.getAbsolutePath(), verbosity);
607
	                if (!delete(f)) {
608
	                    String message = "Unable to delete file "
609
	                        + f.getAbsolutePath();
610
	                    if (failonerror) {
611
	                        throw new BuildException(message);
612
	                    }
613
	                    log(message,
614
	                            quiet ? Project.MSG_VERBOSE : Project.MSG_WARN);
615
	                }
616
	            }
617
	        }
618
    	}
602
        log("Deleting directory " + d.getAbsolutePath(), verbosity);
619
        log("Deleting directory " + d.getAbsolutePath(), verbosity);
603
        if (!delete(d)) {
620
        if (!delete(d)) {
604
            String message = "Unable to delete directory "
621
            String message = "Unable to delete directory "
Lines 605-614 Link Here
605
                + dir.getAbsolutePath();
622
                + dir.getAbsolutePath();
606
            if (failonerror) {
623
            if (failonerror) {
607
                throw new BuildException(message);
624
                throw new BuildException(message);
608
            } else {
609
                log(message,
610
                    quiet ? Project.MSG_VERBOSE : Project.MSG_WARN);
611
            }
625
            }
626
            log(message, quiet ? Project.MSG_VERBOSE : Project.MSG_WARN);
612
        }
627
        }
613
    }
628
    }
614
629

Return to bug 36658