I was just following that because it was already in there, and there was
a "verbose" option in the task, so I figured that's how it was used.
Here's the new path.
On Wed, 2003-10-08 at 11:50, Martin Aliger wrote:
> if (verbose) {
> Log(Level.Info,
> LogPrefix + "Deleting directory '{0}'.",
> path);
> }
>
> should be
>
> Log(Level.Verbose,
> LogPrefix + "Deleting directory '{0}'.",
> path);
>
>
> Martin
>
> -- Original Message --
> From: "Met @ Uber" <[EMAIL PROTECTED]>
> To: "NAnt-Devel" <[EMAIL PROTECTED]>
> Sent: Wednesday, October 08, 2003 5:26 PM
> Subject: Re: [nant-dev] DeleteTask Patch
>
>
> > Patch is attached.
> >
> > On Wed, 2003-10-08 at 10:48, Ian MacLean wrote:
> > > Sounds useful. Post away.
> > >
> > > Ian
> > > Met @ Uber wrote:
> > >
> > > >The patch I'm talking about is hardly important, its just a cleanup of
> > > >the logic and code within DeleteTask.cs. I was trying to figure out
> why
> > > >directory and file deletion were displaying different (messages), so I
> > > >went in and took. I cleaned up the logic a lot so that everything is
> > > >consistent, as far as I am concerned. It should be more efficient as a
> > > >result.
> > > >
> > > >If you want it, let me know, else I'll suck it up ;-)
> > > >
> > > >~ Matthew
> > > >
> > > >
> > > >
> > > >--
> > > >This sf.net email is sponsored by:ThinkGeek
> > > >Welcome to geek heaven.
> > > >http://thinkgeek.com/sf
> > > >_______________________________________________
> > > >nant-developers mailing list
> > > >[EMAIL PROTECTED]
> > > >https://lists.sourceforge.net/lists/listinfo/nant-developers
> > > >
> > > >
> > >
> > >
> > >
> >
>
>
>
>
> --
> This SF.net email is sponsored by: SF.net Giveback Program.
> SourceForge.net hosts over 70,000 Open Source Projects.
> See the people who have HELPED US provide better services:
> Click here: http://sourceforge.net/supporters.php
> _______________________________________________
> nant-developers mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/nant-developers
Index: DeleteTask.cs
===================================================================
RCS file: /cvsroot/nant/nant/src/NAnt.Core/Tasks/DeleteTask.cs,v
retrieving revision 1.17
diff -u -r1.17 DeleteTask.cs
--- DeleteTask.cs 23 Aug 2003 13:31:34 -0000 1.17
+++ DeleteTask.cs 8 Oct 2003 16:13:08 -0000
@@ -16,6 +16,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Gerry Shaw ([EMAIL PROTECTED])
+// Matthew Metnetsky ([EMAIL PROTECTED])
using System;
using System.IO;
@@ -118,9 +119,11 @@
#region Override implementation of Task
protected override void ExecuteTask() {
- // limit task to deleting either a file or a directory or a file set
+ // limit task to deleting either a file, directory, or file set
if (FileName != null && DirectoryName != null) {
- throw new BuildException("Cannot specify 'file' and 'dir' in the same delete task.", Location);
+ string msg = "Cannot specify 'file' and 'dir' in the same " +
+ "delete task.";
+ throw new BuildException(msg, Location);
}
if (FileName != null) {
@@ -129,44 +132,49 @@
try {
path = Project.GetFullPath(FileName);
} catch (Exception e) {
- string msg = String.Format(CultureInfo.InvariantCulture, "Could not determine path from {0}.", FileName);
+ string msg =
+ String.Format(CultureInfo.InvariantCulture,
+ "Could not determine path from '{0}'.",
+ FileName);
throw new BuildException(msg, Location, e);
}
- DeleteFile(path, true);
-
+ DeleteFile(path);
} else if (DirectoryName != null) {
// try to delete specified directory
string path = null;
try {
path = Project.GetFullPath(DirectoryName);
} catch (Exception e) {
- string msg = String.Format(CultureInfo.InvariantCulture, "Could not determine path from {0}.", DirectoryName);
+ string msg =
+ String.Format(CultureInfo.InvariantCulture,
+ "Could not determine path from '{0}'.",
+ DirectoryName);
throw new BuildException(msg, Location, e);
}
- if (!Directory.Exists(path)) {
- string msg = String.Format(CultureInfo.InvariantCulture, "Cannot delete directory {0}. The directory does not exist.", path);
- throw new BuildException(msg, Location);
- }
-
- Log(Level.Info, LogPrefix + "Deleting directory {0}.", path);
RecursiveDeleteDirectory(path);
} else {
- // delete files in fileset
+ // dBelete files in fileset
if (DeleteFileSet.DirectoryNames.Count == 0) {
- Log(Level.Info, LogPrefix + "Deleting {0} files.", DeleteFileSet.FileNames.Count);
+ Log(Level.Info,
+ LogPrefix + "Deleting '{0}' files.",
+ DeleteFileSet.FileNames.Count);
} else if (DeleteFileSet.FileNames.Count == 0) {
- Log(Level.Info, LogPrefix + "Deleting {0} directories.", DeleteFileSet.DirectoryNames.Count);
+ Log(Level.Info,
+ LogPrefix + "Deleting '{0}' directories.",
+ DeleteFileSet.DirectoryNames.Count);
} else {
- Log(Level.Info, LogPrefix + "Deleting {0} files and {1} directories.", DeleteFileSet.FileNames.Count, DeleteFileSet.DirectoryNames.Count);
+ Log(Level.Info,
+ LogPrefix + "Deleting '{0}' files and '{1}' " +
+ "directories.",
+ DeleteFileSet.FileNames.Count,
+ DeleteFileSet.DirectoryNames.Count);
}
foreach (string path in DeleteFileSet.FileNames) {
- DeleteFile(path, Verbose);
+ DeleteFile(path);
}
foreach (string path in DeleteFileSet.DirectoryNames) {
- if (Directory.Exists(path)) {
- RecursiveDeleteDirectory(path);
- }
+ RecursiveDeleteDirectory(path);
}
}
}
@@ -178,34 +186,45 @@
private void RecursiveDeleteDirectory(string path) {
try {
// First, recursively delete all directories in the directory
- string[] dirs = Directory.GetDirectories(path);
- foreach (string dir in dirs)
- RecursiveDeleteDirectory(dir);
-
- // Next, delete all files in the directory
- string[] files = Directory.GetFiles(path);
- foreach (string file in files) {
- try {
- File.SetAttributes(file, FileAttributes.Normal);
- Log(Level.Verbose, LogPrefix + "Deleting file {0}.", file);
- File.Delete(file);
- } catch (Exception e) {
- string msg = String.Format(CultureInfo.InvariantCulture, "Cannot delete file {0}.", file);
- if (FailOnError) {
- throw new BuildException(msg, Location, e);
- }
- Log(Level.Verbose, LogPrefix + msg);
- }
+ if (Directory.Exists(path)) {
+ string[] dirs = Directory.GetDirectories(path);
+ foreach (string dir in dirs) {
+ RecursiveDeleteDirectory(dir);
+ }
+
+ // Next, delete all files in the directory
+ string[] files = Directory.GetFiles(path);
+ foreach (string file in files) {
+ try {
+ Log(Level.Verbose,
+ LogPrefix + "Deleting file '{0}'.",
+ file);
+ DeleteFile(file);
+ } catch (Exception e) {
+ string msg =
+ String.Format(CultureInfo.InvariantCulture,
+ "Cannot delete file '{0}'.",
+ file);
+ Log(Level.Verbose, LogPrefix + msg);
+ if (FailOnError) {
+ throw new BuildException(msg, Location, e);
+ }
+ }
+ }
+
+ // Finally, delete the directory
+ File.SetAttributes(path, FileAttributes.Normal);
+ Log(Level.Info,
+ LogPrefix + "Deleting directory '{0}'.",
+ path);
+ Directory.Delete(path);
}
-
- // Finally, delete the directory
- File.SetAttributes(path, FileAttributes.Normal);
- Log(Level.Verbose, LogPrefix + "Deleting directory {0}.", path);
- Directory.Delete(path);
} catch (BuildException e) {
throw e;
} catch (Exception e) {
- string msg = String.Format(CultureInfo.InvariantCulture, "Cannot delete directory {0}.", path);
+ string msg = String.Format(CultureInfo.InvariantCulture,
+ "Cannot delete directory '{0}'.",
+ path);
if (FailOnError) {
throw new BuildException(msg, Location, e);
}
@@ -213,22 +232,28 @@
}
}
- private void DeleteFile(string path, bool verbose) {
+ private void DeleteFile(string path) {
try {
FileInfo deleteInfo = new FileInfo(path);
if (deleteInfo.Exists) {
- if (verbose) {
- Log(Level.Info, LogPrefix + "Deleting file {0}.", path);
- }
+ Log(Level.Info, LogPrefix + "Deleting file '{0}'.", path);
if (deleteInfo.Attributes != FileAttributes.Normal) {
- File.SetAttributes(deleteInfo.FullName, FileAttributes.Normal);
+ File.SetAttributes(deleteInfo.FullName,
+ FileAttributes.Normal);
}
File.Delete(path);
} else {
- throw new FileNotFoundException();
+ string msg =
+ String.Format(CultureInfo.InvariantCulture,
+ "Cannot delete file '{0}' because it " +
+ "does not exist.",
+ path);
+ throw new BuildException(msg, Location);
}
} catch (Exception e) {
- string msg = String.Format(CultureInfo.InvariantCulture, "Cannot delete file {0}.", path);
+ string msg = String.Format(CultureInfo.InvariantCulture,
+ "Cannot delete file '{0}'.",
+ path);
if (FailOnError) {
throw new BuildException(msg, Location, e);
}