[Mono-bugs] [Bug 354397] New: System.IO.Directory. GetFileSystemEntries does not parse multiple paths.
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Thu Jan 17 06:13:33 EST 2008
https://bugzilla.novell.com/show_bug.cgi?id=354397
Summary: System.IO.Directory.GetFileSystemEntries does not parse
multiple paths.
Product: Mono: Class Libraries
Version: 1.2.6
Platform: All
URL: http://www.bookbookbookbook.com/
OS/Version: All
Status: NEW
Severity: Normal
Priority: P5 - None
Component: System
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: rthijssen at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: Third Party Developer/Partner
Created an attachment (id=190822)
--> (https://bugzilla.novell.com/attachment.cgi?id=190822)
Patched directory.cs
If System.IO.Directory.GetFileSystemEntries is called with a path parameter
containing the PathSeparator and/or more than one path it will throw an
System.IO.DirectoryNotFoundException.
I believe the behaviour should be to parse each path.
For example:
If the path parameter contains the string "/path1;/path2" the output should
contain file system entries for both /path1 and /path2.
The method in System.IO.Directory can be modified as follows to correct this
behaviour:
private static string[] GetFileSystemEntries(string path, string pattern,
FileAttributes mask, FileAttributes attrs)
{
if (path == null || pattern == null)
throw new ArgumentNullException();
if (pattern == String.Empty)
return new string[] { };
if (path.Trim() == "")
throw new ArgumentException("The Path does not have a valid format");
if (path.IndexOf(Path.PathSeparator) > -1)
{
string[] paths = path.Split(new char[] {Path.PathSeparator},
StringSplitOptions.RemoveEmptyEntries);
string[][] allEntries = new string[paths.Length][];
int c = 0;
for (int i = 0; i < paths.Length; i ++)
{
allEntries[i] = GetFileSystemEntries(paths[i], pattern, mask,
attrs);
c += allEntries[i].Length;
}
string[] fileSystemEntries = new string[c];
int index = 0;
for (int i = 0; i < paths.Length; i++)
foreach (string s in allEntries[i])
fileSystemEntries[index++] = s;
return fileSystemEntries;
}
string wild = Path.Combine(path, pattern);
string wildpath = Path.GetDirectoryName(wild);
if (wildpath.IndexOfAny(Path.InvalidPathChars) != -1)
throw new ArgumentException("Path contains invalid characters");
if (wildpath.IndexOfAny(Path.InvalidPathChars) != -1)
{
if (path.IndexOfAny(SearchPattern.InvalidChars) == -1)
throw new ArgumentException("Path contains invalid characters",
"path");
throw new ArgumentException("Pattern contains invalid characters",
"pattern");
}
MonoIOError error;
if (!MonoIO.ExistsDirectory(wildpath, out error))
{
if (error == MonoIOError.ERROR_SUCCESS)
{
MonoIOError file_error;
if (MonoIO.ExistsFile(wildpath, out file_error))
{
return new string[] { wildpath };
}
}
if (error != MonoIOError.ERROR_PATH_NOT_FOUND)
throw MonoIO.GetException(wildpath, error);
if (wildpath.IndexOfAny(SearchPattern.WildcardChars) == -1)
throw new DirectoryNotFoundException("Directory '" + wildpath + "'
not found.");
if (path.IndexOfAny(SearchPattern.WildcardChars) == -1)
throw new ArgumentException("Pattern is invalid", "pattern");
throw new ArgumentException("Path is invalid", "path");
}
string path_with_pattern = Path.Combine(wildpath, pattern);
string[] result = MonoIO.GetFileSystemEntries(path, path_with_pattern,
(int)attrs, (int)mask, out error);
if (error != 0)
throw MonoIO.GetException(wildpath, error);
return result;
}
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list