All,

I've made a change to the DeleteTask that I would like to have
reviewed/committed if you all agree with the change.

This issue I ran into was forcing a delete even if the file is read only.  I
added a parameter "force" that will allow this.  I also added code that would
recurse a directory and "force" the deletion of a directory even if some of the
files in the directory are read only.

Let me know what you all think of this.

Thanks,

Aaron

--- DeleteTask.cs       Fri Jan 17 23:56:22 2003
+++ .\Original\DeleteTask.cs    Wed Feb 05 20:36:33 2003
@@ -19,7 +19,7 @@
 
 using System;
 using System.IO;
-using System.Collections;
+
 using SourceForge.NAnt.Attributes;
 
 namespace SourceForge.NAnt.Tasks {
@@ -51,8 +51,7 @@
     public class DeleteTask : Task {
         
         string _file = null;       
-        string _dir = null;
-               bool _force = false;
+        string _dir = null;               
         FileSet _fileset = new FileSet();
 
         /// <summary>The file to delete.</summary>
@@ -61,15 +60,6 @@
             get { return _file; }
             set {_file = value; }
         }
-
-               /// <summary>Delete files even if read only.</summary>
-               [TaskAttribute("force")]
-               [BooleanValidator()]
-               public bool ForceDelete
-               {
-                       get { return _force; }
-                       set {_force = value; }
-               }
         
         /// <summary>The directory to delete.</summary>
         [TaskAttribute("dir")]
@@ -130,14 +120,7 @@
                     }
 
                     Log.WriteLine(LogPrefix + "Deleting directory {0}", path);
-                                       if( ForceDelete )
-                                       {
-                                               foreach(string file in
getRecursiveFileList(path) )
-                                               {
-                                                       File.SetAttributes(file,
FileAttributes.Normal);
-                                               }
-                                       }
-                                       Directory.Delete(path, true);
+                    Directory.Delete(path, true);
                 } else {
                     throw new DirectoryNotFoundException();
                 }
@@ -149,33 +132,10 @@
             }
         }
 
-               private ArrayList getRecursiveFileList(string path)
-               {
-                       ArrayList files = new ArrayList();
-
-                       string[] dirs = Directory.GetDirectories(path);
-
-                       foreach (string dir in dirs) 
-                       {
-                               files.AddRange( getRecursiveFileList(dir) );
-                       }
-
-                       if( ! path.Equals(".") )
-                       {
-                               files.AddRange(Directory.GetFiles(path));
-                       }
-
-                       return files;
-               }
-
         void DeleteFile(string path, bool verbose) {
             try {
                 if (File.Exists(path)) {
                     Log.WriteLineIf(verbose, LogPrefix + "Deleting file {0}",
path);
-                                       if( ForceDelete )
-                                       {
-                                               File.SetAttributes(path,
FileAttributes.Normal);
-                                       }
                     File.Delete(path);
                 } else {
                     throw new FileNotFoundException();


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Nant-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers

Reply via email to