dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO Directory.cs,1.9,1


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO Directory.cs,1.9,1.10 File.cs,1.11,1.12
Date: Fri, 20 Dec 2002 22:45:29 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO
In directory subversions:/tmp/cvs-serv28090/runtime/System/IO

Modified Files:
        Directory.cs File.cs 
Log Message:
Cleanup exceptions in IO and throw them down from the right towers.


Index: Directory.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/Directory.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** Directory.cs        18 Dec 2002 03:23:42 -0000      1.9
--- Directory.cs        21 Dec 2002 03:45:27 -0000      1.10
***************
*** 48,61 ****
                public static void Delete(string path, bool recursive)
                {
!                       if(path==null)
!                       {
!                               throw new ArgumentNullException();
!                       }
!                       if(path.Length==0 || (path.Trim()).Length==0 || 
!                                                       
path.IndexOfAny(Path.InvalidPathChars)!= -1)
!                       {
!                               throw new ArgumentException();
!                       }
! 
                        // remove any trailing directory sep characters
                        if(path.GetChar(path.Length-1) == 
Path.DirectorySeparatorChar)
--- 48,54 ----
                public static void Delete(string path, bool recursive)
                {
!                       Exception e=ValidatePath(path,"path");
!                       if(e != null) throw e;
!       
                        // remove any trailing directory sep characters
                        if(path.GetChar(path.Length-1) == 
Path.DirectorySeparatorChar)
***************
*** 114,126 ****
                public static bool Exists(string path)
                {
!                       if(path.Length==0 || (path.Trim()).Length==0 || 
!                                               
path.IndexOfAny(pathinfo.invalidPathChars)!= -1)
!                       {       
!                               throw new ArgumentException();
!                       }
!                       if (path == null)
!                       {
!                               return false;
!                       }       
                        long ac;
                        Errno errno = DirMethods.GetLastAccess(path, out ac);
--- 107,112 ----
                public static bool Exists(string path)
                {
!                       Exception e=ValidatePath(path,"path");
!                       if(e != null) throw e;
                        long ac;
                        Errno errno = DirMethods.GetLastAccess(path, out ac);
***************
*** 148,187 ****
                }
  
!               private static void VerifyDirectoryAccess(String path)
!               {
!                       if(path.Length==0 || (path.Trim()).Length==0 || 
(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;
                        }
                }
  
                public static string GetCurrentDirectory()
                {
                        return DirMethods.GetCurrentDirectory();
                }
--- 134,157 ----
                }
  
!               private static Exception GetErrnoExceptions(Errno errno,String 
path)
                {
                        switch(errno)
                        {
                                case Errno.ENOENT:
!                                       return new 
DirectoryNotFoundException(_("IO_DirNotFound"));
                                case Errno.ENOTDIR:
!                                       return new 
IOException(String.Format(_("IO_IsNotDir"),
!                                                                               
        path));
                                case Errno.EACCES:
!                                       return new 
SecurityException(_("IO_PathnameSecurity"));
                                case Errno.ENAMETOOLONG:
!                                       return new PathTooLongException();
                        }
+                       return null;
                }
  
                public static string GetCurrentDirectory()
                {
+                       // TODO: security ?
                        return DirMethods.GetCurrentDirectory();
                }
***************
*** 189,200 ****
                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);
                }
  
--- 159,184 ----
                public static string[] GetDirectories(string path)
                {
!                       try
!                       {
!                               return InternalGetDirectoryEntries(path,"*",
                                                                                
FileType.directory);
+                       }
+                       catch(Exception e)
+                       {
+                               throw e; // re-source exception to be like ECMA
+                       }
                }
  
                public static string[] GetDirectories(string path, string 
searchPattern)
                {
!                       try
!                       {
!                               return 
InternalGetDirectoryEntries(path,searchPattern,
                                                                                
FileType.directory);
+                       }
+                       catch(Exception e)
+                       {
+                               throw e;
+                       }
                }
  
***************
*** 208,213 ****
                public static string[] GetFileSystemEntries(string path)
                {
!                       return InternalGetDirectoryEntries(path,"*",
                                                                                
                (FileType)(-1)); // all types
                }
  
--- 192,204 ----
                public static string[] GetFileSystemEntries(string path)
                {
!                       try
!                       {
!                               return InternalGetDirectoryEntries(path,"*",
                                                                                
                (FileType)(-1)); // all types
+                       }
+                       catch(Exception e)
+                       {
+                               throw e;
+                       }
                }
  
***************
*** 215,220 ****
                                                                                
                        string searchPattern)
                {
!                       return InternalGetDirectoryEntries(path,searchPattern,
                                                                                
                                (FileType)(-1));
                }
  
--- 206,218 ----
                                                                                
                        string searchPattern)
                {
!                       try
!                       {
!                               return 
InternalGetDirectoryEntries(path,searchPattern,
                                                                                
                                (FileType)(-1));
+                       }
+                       catch(Exception e)
+                       {
+                               throw e;
+                       }
                }
  
***************
*** 222,233 ****
                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);
                }
        
--- 220,245 ----
                public static string[] GetFiles(string path)
                {
!                       try
!                       {
!                               return InternalGetDirectoryEntries(path,"*",
                                                                                
FileType.regularFile);
+                       }
+                       catch(Exception e)
+                       {
+                               throw e;
+                       }
                }
  
                public static string[] GetFiles(string path, string 
searchPattern)
                {
!                       try
!                       {
!                               return 
InternalGetDirectoryEntries(path,searchPattern,
                                                                                
FileType.regularFile);
+                       }
+                       catch(Exception e)
+                       {
+                               throw e;
+                       }
                }
        
***************
*** 236,243 ****
                                                                                
                                FileType type)
                {
!                       VerifyDirectoryAccess(path);
                        InternalFileInfo []dirEnts;
                        Errno errno=DirMethods.GetFilesInDirectory(path,out 
dirEnts);
!                       ThrowErrnoExceptions(errno,path);
                        GlobMatch fnmatch = new GlobMatch(searchPattern);
                        
--- 248,260 ----
                                                                                
                                FileType type)
                {
!                       Exception e=ValidatePath(path,"path");
!                       if(e != null) throw e;
! 
                        InternalFileInfo []dirEnts;
                        Errno errno=DirMethods.GetFilesInDirectory(path,out 
dirEnts);
!                       
!                       e=GetErrnoExceptions(errno,path);
!                       if(e != null) throw e;
!                       
                        GlobMatch fnmatch = new GlobMatch(searchPattern);
                        
***************
*** 268,291 ****
                public static void Move(string sourceDirName, string 
destDirName)
                {
!                       if(sourceDirName==null)
!                       {
!                               throw new 
ArgumentNullException("sourceDirName");
!                       }
!                       if(destDirName ==null)
!                       {
!                               throw new ArgumentNullException("destDirName");
!                       }
!                       if(sourceDirName.Length==0 || 
(sourceDirName.Trim()).Length==0 || 
!                               
sourceDirName.IndexOfAny(Path.InvalidPathChars)!= -1)
!                       {
!                               throw new ArgumentException("sourceDirName");
!                       }
!                       if(destDirName.Length==0 || 
(destDirName.Trim()).Length==0 || 
!                               destDirName.IndexOfAny(Path.InvalidPathChars)!= 
-1)
!                       {
!                               throw new ArgumentException("destDirName");
!                       }
                        Errno errno = DirMethods.Rename(sourceDirName, 
destDirName);
!                       ThrowErrnoExceptions(errno, sourceDirName);
                }
  
--- 285,297 ----
                public static void Move(string sourceDirName, string 
destDirName)
                {
!                       Exception e=ValidatePath(sourceDirName,"sourceDirName");
!                       if(e != null) throw e;
! 
!                       e=ValidatePath(destDirName,"destDirName");
!                       if(e != null) throw e;
!                       
                        Errno errno = DirMethods.Rename(sourceDirName, 
destDirName);
!                       e=GetErrnoExceptions(errno, sourceDirName);
!                       if(e != null) throw e;
                }
  
***************
*** 293,304 ****
                public static void SetCreationTime(string path, DateTime 
creationTime)
                {
                }
  
                public static void SetCurrentDirectory(string path)
                {
!                       if(path==null)
!                               throw new ArgumentNullException("path");
                        Errno errno=DirMethods.ChangeDirectory(path);
!                       ThrowErrnoExceptions(errno,path);
                }
  
--- 299,315 ----
                public static void SetCreationTime(string path, DateTime 
creationTime)
                {
+                       Exception e=ValidatePath(path,"path");
+                       if(e != null) throw e;
                }
  
                public static void SetCurrentDirectory(string path)
                {
!                       Exception e=ValidatePath(path,"path");
!                       if(e != null) throw e;
!                       
                        Errno errno=DirMethods.ChangeDirectory(path);
! 
!                       e=GetErrnoExceptions(errno,path);
!                       if(e != null) throw e;
                }
  
***************
*** 306,309 ****
--- 317,322 ----
                public static void SetLastAccessTime(string path, DateTime 
lastAccessTime)
                {
+                       Exception e=ValidatePath(path,"path");
+                       if(e != null) throw e;
                }
  
***************
*** 311,314 ****
--- 324,329 ----
                public static void SetLastWriteTime(string path, DateTime 
lastWriteTime)
                {
+                       Exception e=ValidatePath(path,"path");
+                       if(e != null) throw e;
                }
                
***************
*** 396,400 ****
                } // class GlobMatch
  
! 
        } // class Directory 
  } // namespace System.IO
--- 411,427 ----
                } // class GlobMatch
  
!               private static Exception ValidatePath(string path,string name)
!               {
!                       if (path == null)
!                       {
!                               return new 
ArgumentNullException(_("Arg_NotNull"),name);
!                       }
!                       if ((path.Trim() == "") || 
!(FileMethods.ValidatePathname(path))
!                               || path.IndexOfAny(Path.InvalidPathChars)!=-1)
!                       {
!                               return new 
ArgumentException(_("IO_InvalidPathname"),name);
!                       }
!                       return null;
!               }
        } // class Directory 
  } // namespace System.IO

Index: File.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/File.cs,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** File.cs     21 Dec 2002 03:02:06 -0000      1.11
--- File.cs     21 Dec 2002 03:45:27 -0000      1.12
***************
*** 41,44 ****
--- 41,48 ----
                public static void Copy(string source, string dest) 
                {
+                       Exception e = ValidatePath(source);
+                       if (e != null) { throw e; }
+                       e = ValidatePath(dest);
+                       if (e != null) { throw e; }
                        Copy(source, dest, false);
                }
***************
*** 48,69 ****
                {
                        
!                       if (source == null) 
!                       {
!                               throw new ArgumentNullException("source");
!                       }
!                       if (dest == null)
!                       {
!                               throw new ArgumentNullException("dest");
!                       }
!                       
!                       if (!FileMethods.ValidatePathname(source)) 
!                       {
!                               throw new 
ArgumentException(_("IO_InvalidPathname"), "source");
!                       }
! 
!                       if (!FileMethods.ValidatePathname(dest)) 
!                       {
!                               throw new 
ArgumentException(_("IO_InvalidPathname"), "dest");
!                       }
  
                        Errno err = DirMethods.Copy(source, dest);
--- 52,59 ----
                {
                        
!                       Exception e = ValidatePath(source);
!                       if (e != null) { throw e; }
!                       e = ValidatePath(dest);
!                       if (e != null) { throw e; }
  
                        Errno err = DirMethods.Copy(source, dest);
***************
*** 130,142 ****
                public static void Delete(string path) 
                {
!                       if (path == null) 
!                       {
!                               throw new ArgumentNullException("path");
!                       }
!               
!                       if (!FileMethods.ValidatePathname(path)) 
!                       {
!                               throw new 
ArgumentException(_("IO_InvalidPathname"), "path");
!                       }
                
                        Errno err = DirMethods.Delete(path);
--- 120,125 ----
                public static void Delete(string path) 
                {
!                       Exception e = ValidatePath(path);
!                       if (e != null) { throw e; }
                
                        Errno err = DirMethods.Delete(path);
***************
*** 172,179 ****
                public static bool Exists(string path) 
                {
                        return FileMethods.Exists(path);        
                }
                
-               [TODO]
                public static DateTime GetCreationTime(string path)
                {
--- 155,163 ----
                public static bool Exists(string path) 
                {
+                       Exception e = ValidatePath(path);
+                       if (e != null) { throw e; }
                        return FileMethods.Exists(path);        
                }
                
                public static DateTime GetCreationTime(string path)
                {
***************
*** 181,185 ****
                        // afaik, some System.Security stuff needs to be added 
here - Rich
  
!                       Exception e = GetTimeValidatePath(path);
                        if (e != null) { throw e; }
  
--- 165,169 ----
                        // afaik, some System.Security stuff needs to be added 
here - Rich
  
!                       Exception e = ValidatePath(path);
                        if (e != null) { throw e; }
  
***************
*** 191,195 ****
                }
  
-               [TODO]
                public static DateTime GetLastAccessTime(string path)
                {
--- 175,178 ----
***************
*** 197,201 ****
                        // afaik, some System.Security stuff needs to be added 
here - Rich
  
!                       Exception e = GetTimeValidatePath(path);
                        if (e != null) { throw e; }
  
--- 180,184 ----
                        // afaik, some System.Security stuff needs to be added 
here - Rich
  
!                       Exception e = ValidatePath(path);
                        if (e != null) { throw e; }
  
***************
*** 207,211 ****
                }
  
-               [TODO]
                public static DateTime GetLastWriteTime(string path)
                {
--- 190,193 ----
***************
*** 213,217 ****
                        // afaik, some System.Security stuff needs to be added 
here - Rich
  
!                       Exception e = GetTimeValidatePath(path);
                        if (e != null) { throw e; }
  
--- 195,199 ----
                        // afaik, some System.Security stuff needs to be added 
here - Rich
  
!                       Exception e = ValidatePath(path);
                        if (e != null) { throw e; }
  
***************
*** 225,228 ****
--- 207,215 ----
                public static void Move(string src, string dest)
                {
+                       Exception e = ValidatePath(src);
+                       if (e != null) { throw e; }
+                       e = ValidatePath(dest);
+                       if (e != null) { throw e; }
+ 
                        DirMethods.Rename(src, dest);
                }
***************
*** 303,307 ****
                        }
                }
!               private static Exception GetTimeValidatePath(string path)
                {
                        if (path == null)
--- 290,294 ----
                        }
                }
!               private static Exception ValidatePath(string path)
                {
                        if (path == null)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]