[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO Directory.cs,1.5,1.
From: |
Gopal.V <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO Directory.cs,1.5,1.6 Path.cs,1.9,1.10 |
Date: |
Fri, 22 Nov 2002 05:36:14 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO
In directory subversions:/tmp/cvs-serv595/runtime/System/IO
Modified Files:
Directory.cs Path.cs
Log Message:
Directory.GetFileSystemEntries and similar
Index: Directory.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/Directory.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** Directory.cs 11 Nov 2002 06:06:28 -0000 1.5
--- Directory.cs 22 Nov 2002 10:36:12 -0000 1.6
***************
*** 25,28 ****
--- 25,31 ----
{
using System;
+ using System.Text;
+ using System.Private;
+ using System.Collections;
using System.Security;
using Platform;
***************
*** 124,127 ****
--- 127,165 ----
}
+ private static void VerifyDirectoryAccess(String path)
+ {
+ if(path.Length==0 || (path.Trim()).Length==0)
+ //FIXME: ||
path.IndexOfAny(pathinfo.invalidPathChars)!= -1)
+ {
+ throw new ArgumentException();
+ }
+ if (path == null)
+ {
+ throw new ArgumentNullException("path");
+ }
+ long ac;
+ Errno errno = DirMethods.GetLastAccess(path, out ac);
+ ThrowErrnoExceptions(errno,path);
+ }
+
+ private static void ThrowErrnoExceptions(Errno errno,String
path)
+ {
+ switch(errno)
+ {
+ case Errno.Success:
+ return;
+ case Errno.ENOENT:
+ throw new
DirectoryNotFoundException(_("IO_DirNotFound"));
+ case Errno.ENOTDIR:
+ throw new
IOException(String.Format(_("IO_IsNotDir"),path));
+ case Errno.EACCES:
+ throw new
SecurityException(_("IO_PathnameSecurity"));
+ case Errno.ENAMETOOLONG:
+ throw new PathTooLongException();
+ default:
+ return;
+ }
+ }
+
[TODO]
public static string GetCurrentDirectory()
***************
*** 130,173 ****
}
- [TODO]
public static string[] GetDirectories(string path)
{
! return null;
}
- [TODO]
public static string[] GetDirectories(string path, string
searchPattern)
{
! return null;
}
- [TODO]
public static string GetDirectoryRoot(string path)
{
! return null;
}
- [TODO]
public static string[] GetFileSystemEntries(string path)
{
! return null;
}
! [TODO]
! public static string[] GetFileSystemEntries(string path, string
searchPattern)
{
! return null;
}
! [TODO]
public static string[] GetFiles(string path)
{
! return null;
}
- [TODO]
public static string[] GetFiles(string path, string
searchPattern)
{
! return null;
}
--- 168,238 ----
}
public static string[] GetDirectories(string path)
{
! return InternalGetDirectoryEntries(path,"*",
!
FileType.directory);
}
public static string[] GetDirectories(string path, string
searchPattern)
{
! return InternalGetDirectoryEntries(path,searchPattern,
!
FileType.directory);
}
public static string GetDirectoryRoot(string path)
{
! // no difference except for "\\ecmatest"
! // in Directory shoud give "C:\\" and in Path should
give "\\"
! return Path.GetPathRoot(path);
}
public static string[] GetFileSystemEntries(string path)
{
! return InternalGetDirectoryEntries(path,"*",
!
(FileType)(-1)); // all types
}
! public static string[] GetFileSystemEntries(string path,
!
string searchPattern)
{
! return InternalGetDirectoryEntries(path,searchPattern,
!
(FileType)(-1));
}
!
public static string[] GetFiles(string path)
{
! return InternalGetDirectoryEntries(path,"*",
!
FileType.regularFile);
}
public static string[] GetFiles(string path, string
searchPattern)
{
! return InternalGetDirectoryEntries(path,searchPattern,
!
FileType.regularFile);
! }
!
! private static String[] InternalGetDirectoryEntries(String path,
!
String searchPattern,
!
FileType type)
! {
! VerifyDirectoryAccess(path);
! InternalFileInfo []dirEnts;
! Errno errno=DirMethods.GetFilesInDirectory(path,out
dirEnts);
! ThrowErrnoExceptions(errno,path);
! GlobMatch fnmatch = new GlobMatch(searchPattern);
!
! ArrayList list=new ArrayList(dirEnts.Length);
! foreach(InternalFileInfo info in dirEnts)
! {
! if(fnmatch.Match(info.fileName)
! && (type == (FileType)(-1)
|| info.fileType == type ))
! {
! list.Add(info.fileName);
! }
! }
! String[] retval=new String[list.Count];
! list.CopyTo(retval);
! return retval;
}
***************
*** 206,210 ****
{
}
! }
! }
--- 271,359 ----
{
}
+
+ /* internal class to convert Glob expression to Regexp */
+ private class GlobMatch : IDisposable
+ {
+ Regexp expr;
+ String pattern;
+ String translated;
+ bool disposed=false;
+
+ internal GlobMatch(String glob)
+ {
+ StringBuilder builder=new StringBuilder();
+ pattern=glob;
+ char[] arr=glob.ToCharArray();
+ for(int i=0;i<arr.Length;i++)
+ {
+ switch(arr[i])
+ {
+ case '.':
+ {
+ if(i < arr.Length-1)
+ {
+
if(arr[i+1]=='?')
+ {
+
builder.Append("\\.{0,1}");
+ i=i+1;
+ }
+ else
if(arr[i+1]=='*')
+ {
+
builder.Append(".*");
+ i=i+1;
+ }
+ else
+ {
+
builder.Append("\\.");
+ }
+ }
+ else
+ {
+
builder.Append("\\.");
+ }
+ }
+ break;
+ case '*':
+ builder.Append(".*");
+ break;
+ case '?':
+ builder.Append(".");
+ break;
+ case '[':
+ case ']':
+ case '^':
+ case '\\':
+ builder.Append("\\"+arr[i]);
+ break;
+ default:
+ builder.Append(arr[i]);
+ break;
+ }
+ }
+ translated="^"+builder.ToString()+"$";
//perfect match
+ expr=new Regexp(translated);
+ }
+
+ public bool Match(String input)
+ {
+ if(input==null)
+ throw new
ArgumentNullException("input");
+ return expr.Match(input);
+ }
+
+ public void Dispose()
+ {
+ if(!disposed)expr.Dispose();
+ disposed=true;
+ }
+
+ void IDisposable.Dispose()
+ {
+ this.Dispose();
+ }
+
+ } // class GlobMatch
+
! } // class Directory
! } // namespace System.IO
Index: Path.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/Path.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** Path.cs 30 Oct 2002 12:27:58 -0000 1.9
--- Path.cs 22 Nov 2002 10:36:12 -0000 1.10
***************
*** 223,227 ****
/* generate /tmp/pnetXXXXXX */
! public static String GetTempFilename()
{
String dir = GetTempPath();
--- 223,227 ----
/* generate /tmp/pnetXXXXXX */
! public static String GetTempFileName()
{
String dir = GetTempPath();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO Directory.cs,1.5,1.6 Path.cs,1.9,1.10,
Gopal.V <address@hidden> <=