Canonicalize excludepaths

Nov 7, 2007 at 6:59 PM
Thanks for writing this tool (and sharing it with the rest of us).

I ran into an issue when using a build macro to pass in an excludepath to the tool. The build macros append a \ on the paths (I was using $(TargetDir)), but when directory names are processed by .net they don't have the trailing \, so when the path was compared in the method below it wasn't matching correctly. I addresses this in my local build but I'd love it if you could roll it up into the main code stream so I can continue to benefit from your work :) Code change is below in bold.

Cheers.

public static bool IncludeDir(DirectoryInfo dirInfo)
{
if (dirInfo == null)
{
return false;
}
// Do not include the directory if its hidden
if ((dirInfo.Attributes & FileAttributes.Hidden) != 0)
{
return false;
}
bool include = true;
foreach (string exludepath in Config.Current.Excludepaths)
{
if (dirInfo.FullName.StartsWith(Path.GetDirectoryName(exludepath), StringComparison.InvariantCultureIgnoreCase))
{
include = false;
break;
}
}
return include;
}
Coordinator
Nov 16, 2007 at 9:41 AM
I'll include this in the next release of WSPBuilder.

Thank you
Keutmann


babgvant wrote:
Thanks for writing this tool (and sharing it with the rest of us).

I ran into an issue when using a build macro to pass in an excludepath to the tool. The build macros append a \ on the paths (I was using $(TargetDir)), but when directory names are processed by .net they don't have the trailing \, so when the path was compared in the method below it wasn't matching correctly. I addresses this in my local build but I'd love it if you could roll it up into the main code stream so I can continue to benefit from your work :) Code change is below in bold.

Cheers.

public static bool IncludeDir(DirectoryInfo dirInfo)
{
if (dirInfo == null)
{
return false;
}
// Do not include the directory if its hidden
if ((dirInfo.Attributes & FileAttributes.Hidden) != 0)
{
return false;
}
bool include = true;
foreach (string exludepath in Config.Current.Excludepaths)
{
if (dirInfo.FullName.StartsWith(Path.GetDirectoryName(exludepath), StringComparison.InvariantCultureIgnoreCase))
{
include = false;
break;
}
}
return include;
}

Feb 5, 2008 at 4:08 PM
0.9.8.0109 still has this issue. Just letting you know btw, this tool saves me so much time I don't mind modifying it at all with new releases.

Thanks.
Coordinator
Feb 6, 2008 at 6:36 PM
I have added the following code, that should fix the bug. Because I'm not sure that Path.GetDirectoryName(exludepath) is right choice. The reason is that it may cut of the directory name if there is no \ ... e.g. Path.GetDirectoryName("c:\myfolder\mysubfolder") returns c:\myfolder

string path = (exludepath.EndsWith(@"\")) ? exludepath.Substring(0, exludepath.Length-1) : exludepath;
if (dirInfo.FullName.StartsWith(path, StringComparison.InvariantCultureIgnoreCase))
{
include = false;
break;
}

This fix is in the next release of the WSPBuilder.

/keutmann


babgvant wrote:
0.9.8.0109 still has this issue. Just letting you know btw, this tool saves me so much time I don't mind modifying it at all with new releases.

Thanks.

Feb 6, 2008 at 10:53 PM

keutmann wrote:
I have added the following code, that should fix the bug. Because I'm not sure that Path.GetDirectoryName(exludepath) is right choice. The reason is that it may cut of the directory name if there is no \ ... e.g. Path.GetDirectoryName("c:\myfolder\mysubfolder") returns c:\myfolder

string path = (exludepath.EndsWith(@"\")) ? exludepath.Substring(0, exludepath.Length-1) : exludepath;
if (dirInfo.FullName.StartsWith(path, StringComparison.InvariantCultureIgnoreCase))
{
include = false;
break;
}

This fix is in the next release of the WSPBuilder.

/keutmann



I can live with that :)

Cheers.