I have done a bit of work in mcs/class/corlib/System.IO/Directory.cs
here is the diff.

can i commit?

PD: The diff is so big because i changed the line end format from
windows to unix.
-- 
Eduardo Garcia Cebollero <[EMAIL PROTECTED]>
Index: ChangeLog
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System.IO/ChangeLog,v
retrieving revision 1.115
diff -r1.115 ChangeLog
0a1,11
> 2002-12-11  Eduardo Garcia Cebollero <[EMAIL PROTECTED]>
> 
> 	*Directory.cs: Some Exceptions added, fixed GetParent(),
> 	CreateDirectory() should work with unix, native windows and
> 	windows samba shares.
> 
> 2002-12-08  Eduardo Garcia Cebollero <[EMAIL PROTECTED]>
> 
> 	* Directory.cs: CreateDirectory  works now with Absolute paths
> 	too, not only with relative ones.
> 
Index: Directory.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System.IO/Directory.cs,v
retrieving revision 1.19
diff -r1.19 Directory.cs
1,17c1,18
< // 
< // System.IO.Directory.cs 
< //
< // Authors:
< //   Jim Richardson  ([EMAIL PROTECTED])
< //   Miguel de Icaza ([EMAIL PROTECTED])
< //   Dan Lewis       ([EMAIL PROTECTED])
< //
< // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
< // Copyright (C) 2002 Ximian, Inc.
< // 
< // Created:        Monday, August 13, 2001 
< //
< //------------------------------------------------------------------------------
< 
< using System;
< using System.Security.Permissions;
---
> // 
> // System.IO.Directory.cs 
> //
> // Authors:
> //   Jim Richardson  ([EMAIL PROTECTED])
> //   Miguel de Icaza ([EMAIL PROTECTED])
> //   Dan Lewis       ([EMAIL PROTECTED])
> //   Eduardo Garcia  ([EMAIL PROTECTED])
> //
> // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
> // Copyright (C) 2002 Ximian, Inc.
> // 
> // Created:        Monday, August 13, 2001 
> //
> //------------------------------------------------------------------------------
> 
> using System;
> using System.Security.Permissions;
20,25d20
< 
< namespace System.IO
< {
< 	public sealed class Directory : Object
< 	{
< 		private Directory () {}
26a22,27
> namespace System.IO
> {
> 	public sealed class Directory : Object
> 	{
> 		private Directory () {}
> 		
29d29
< 			StringBuilder pathsumm = new StringBuilder();
43c43
< 
---
> 			
45d44
< 
47c46,47
< 			if (pathcomponents.Length == 1) {
---
> 			
> 			if (pathcomponents.Length == 1){
51c51,52
< 				foreach(string dir in pathcomponents)
---
> 				if ((path[0]== Path.DirectorySeparatorChar) ||
> 				    ((path[1] == ':') && (path[2] == Path.DirectorySeparatorChar))) //Absolute Path						
53,58c54,96
< 					if (dir.Length != 0) {
< 						if (pathsumm.Length == 0) {
< 							pathsumm.Append(dir);
< 						} 
< 						else {
< 							pathsumm.Append(Path.DirectorySeparatorChar + dir);
---
> 					//Should Work in Unix, Win* native Directoryes and Samba Shares
> 					//FIXME: This is not thread safe
> 				    
> 					
> 					string actual_path = Directory.GetCurrentDirectory();
> 					
> 					if (Environment.OSVersion.Platform == PlatformID.Unix) //Is Unix
> 					{
> 						StringBuilder pathsumm = new StringBuilder(path);
> 						Directory.SetCurrentDirectory("/");
> 						pathsumm.Remove(0,1);
> 						tmpinfo = Directory.CreateDirectory(pathsumm.ToString());
> 					}
> 					else //We asume is Win*
> 					{
> 						if ((path[1] == ':') || (path[0] == Path.DirectorySeparatorChar)) //Is a regular path
> 						{
> 							StringBuilder pathsumm = new StringBuilder(path);
> 							Directory.SetCurrentDirectory(path.Substring(0,2));
> 							pathsumm.Remove(0,2);
> 							tmpinfo = Directory.CreateDirectory(pathsumm.ToString());							
> 						}								
> 						else if((path[0] == '\\') && (path[1] == '\\')) //Is a Samba Share
> 						{
> 							if (Directory.Exists(pathcomponents[0] + "\\"
> 									     + pathcomponents[1] + "\\"
> 									     + pathcomponents[2]))
> 							{
> 								StringBuilder pathsumm = new StringBuilder();	
> 								Directory.SetCurrentDirectory(pathcomponents[0] + 
> 											      "\\" + pathcomponents[1] +
> 											      "\\" + pathcomponents[2]);
> 								pathcomponents[0] = ""; pathcomponents[1] = ""; pathcomponents[2] = "";
> 								foreach(string dir in pathsumm.ToString())
> 								{
> 									pathsumm.Append(dir + "\\");
> 								}		
> 								Directory.CreateDirectory(pathsumm.ToString());
> 							}
> 							else
> 							{
> 								throw new DirectoryNotFoundException("The samba share do not Exists");
> 							}
59a98
> 						
60a100,104
> 					Directory.SetCurrentDirectory(actual_path);	
> 				}
> 				else //Relative Path
> 				{
> 					StringBuilder pathsumm = new StringBuilder();
62,63c106,119
< 					if (pathsumm.Length != 0 && !Directory.Exists (pathsumm.ToString())) {
< 						tmpinfo = Directory.RealCreateDirectory (pathsumm.ToString());
---
> 					foreach(string dir in pathcomponents)
> 					{
> 						if (dir.Length != 0) {
> 							if (pathsumm.Length == 0) {
> 								pathsumm.Append (dir);
> 							} 
> 							else {
> 								pathsumm.Append (Path.DirectorySeparatorChar + dir);
> 							}
> 							
> 							if (!Directory.Exists (pathsumm.ToString())) {
> 								tmpinfo = Directory.RealCreateDirectory (pathsumm.ToString());
> 							}
> 						}
102,126c158,184
< 		static void RecursiveDelete (string path)
< 		{
< 			foreach (string dir in GetDirectories (path))
< 				RecursiveDelete (dir);
< 
< 			foreach (string file in GetFiles (path))
< 				File.Delete (file);
< 
< 			Directory.Delete (path);
< 		}
< 		
< 		public static void Delete (string path, bool recurse)
< 		{
< 			if (path == null)
< 				throw new ArgumentNullException ();
< 			if (path.IndexOfAny (Path.InvalidPathChars) != -1)
< 				throw new ArgumentException ("Path contains invalid characters");
< 
< 			if (recurse == false){
< 				Delete (path);
< 				return;
< 			}
< 
< 			RecursiveDelete (path);
< 		}
---
> 		static void RecursiveDelete (string path)
> 		{
> 			foreach (string dir in GetDirectories (path))
> 				RecursiveDelete (dir);
> 
> 			foreach (string file in GetFiles (path))
> 				File.Delete (file);
> 
> 			Directory.Delete (path);
> 		}
> 		
> 		public static void Delete (string path, bool recurse)
> 		{
> 			if (path == null)
> 				throw new ArgumentNullException ();
> 			if (path == "")
> 				throw new System.ArgumentException("Path is Empty");
> 			if (path.IndexOfAny (Path.InvalidPathChars) != -1)
> 				throw new ArgumentException ("Path contains invalid characters");
> 
> 			if (recurse == false){
> 				Delete (path);
> 				return;
> 			}
> 
> 			RecursiveDelete (path);
> 		}
131d188
< 			
135,242c192,314
< 		public static DateTime GetLastAccessTime (string path)
< 		{
< 			return File.GetLastAccessTime (path);
< 		}
< 		
< 		public static DateTime GetLastWriteTime (string path)
< 		{
< 			return File.GetLastWriteTime (path);
< 		}
< 		
< 		public static DateTime GetCreationTime (string path)
< 		{
< 			return File.GetLastWriteTime (path);
< 		}
< 		
< 		public static string GetCurrentDirectory ()
< 		{
< 			/*
< 			// Implementation complete 08/25/2001 14:24 except for
< 			// LAMESPEC: documentation specifies invalid exceptions (i think)
< 			//           also shouldn't need Write to getcurrrent should we?
< 			string str = Environment.CurrentDirectory;
< 			CheckPermission.Demand (FileIOPermissionAccess.Read & FileIOPermissionAccess.Write, str);
< 			*/
< 			return Environment.CurrentDirectory;
< 		}
< 		
< 		public static string [] GetDirectories (string path)
< 		{
< 			return GetDirectories (path, "*");
< 		}
< 		
< 		public static string [] GetDirectories (string path, string pattern)
< 		{
< 			return GetFileSystemEntries (path, pattern, FileAttributes.Directory, FileAttributes.Directory);
< 		}
< 		
< 		public static string GetDirectoryRoot (string path)
< 		{
< 			return "" + Path.DirectorySeparatorChar;
< 		}
< 		
< 		public static string [] GetFiles (string path)
< 		{
< 			return GetFiles (path, "*");
< 		}
< 		
< 		public static string [] GetFiles (string path, string pattern)
< 		{
< 			return GetFileSystemEntries (path, pattern, FileAttributes.Directory, 0);
< 		}
< 
< 		public static string [] GetFileSystemEntries (string path)
< 		{	
< 			return GetFileSystemEntries (path, "*");
< 		}
< 
< 		public static string [] GetFileSystemEntries (string path, string pattern)
< 		{
< 			return GetFileSystemEntries (path, pattern, 0, 0);
< 		}
< 		
< 		public static string[] GetLogicalDrives ()
< 		{	
< 			return new string [] { "A:\\", "C:\\" };
< 		}
< 
< 		public static DirectoryInfo GetParent (string path)
< 		{
< 			return new DirectoryInfo (Path.GetDirectoryName (path));
< 		}
< 
< 		public static void Move (string src, string dest)
< 		{
< 			File.Move (src, dest);
< 		}
< 
< 		public static void SetCreationTime (string path, DateTime creation_time)
< 		{
< 			File.SetCreationTime (path, creation_time);
< 		}
< 		
< 		public static void SetCurrentDirectory (string path)
< 		{
< 			/*
< 			// Implementation complete 08/25/2001 14:24 except for
< 			// LAMESPEC: documentation specifies invalid exceptions IOException (i think)
< 			CheckArgument.Path (path, true);
< 			CheckPermission.Demand (FileIOPermissionAccess.Read & FileIOPermissionAccess.Write, path);	
< 			*/
< 			if (!Exists (path))
< 			{
< 				throw new DirectoryNotFoundException ("Directory \"" + path + "\" not found.");
< 			}
< 			Environment.CurrentDirectory = path;
< 		}
< 
< 		public static void SetLastAccessTime (string path, DateTime last_access_time)
< 		{
< 			File.SetLastAccessTime (path, last_access_time);
< 		}
< 		
< 		public static void SetLastWriteTime (string path, DateTime last_write_time)
< 		{
< 			File.SetLastWriteTime (path, last_write_time);
< 		}
< 		
< 		// private
---
> 		public static DateTime GetLastAccessTime (string path)
> 		{
> 			return File.GetLastAccessTime (path);
> 		}
> 		
> 		public static DateTime GetLastWriteTime (string path)
> 		{
> 			return File.GetLastWriteTime (path);
> 		}
> 		
> 		public static DateTime GetCreationTime (string path)
> 		{
> 			return File.GetLastWriteTime (path);
> 		}
> 		
> 		public static string GetCurrentDirectory ()
> 		{
> 			/*
> 			// Implementation complete 08/25/2001 14:24 except for
> 			// LAMESPEC: documentation specifies invalid exceptions (i think)
> 			//           also shouldn't need Write to getcurrrent should we?
> 			string str = Environment.CurrentDirectory;
> 			CheckPermission.Demand (FileIOPermissionAccess.Read & FileIOPermissionAccess.Write, str);
> 			*/
> 			return Environment.CurrentDirectory;
> 		}
> 		
> 		public static string [] GetDirectories (string path)
> 		{
> 			return GetDirectories (path, "*");
> 		}
> 		
> 		public static string [] GetDirectories (string path, string pattern)
> 		{
> 			return GetFileSystemEntries (path, pattern, FileAttributes.Directory, FileAttributes.Directory);
> 		}
> 		
> 		public static string GetDirectoryRoot (string path)
> 		{
> 			return new String(Path.DirectorySeparatorChar,1);
> 		}
> 		
> 		public static string [] GetFiles (string path)
> 		{
> 			return GetFiles (path, "*");
> 		}
> 		
> 		public static string [] GetFiles (string path, string pattern)
> 		{
> 			return GetFileSystemEntries (path, pattern, FileAttributes.Directory, 0);
> 		}
> 
> 		public static string [] GetFileSystemEntries (string path)
> 		{
> 			return GetFileSystemEntries (path, "*");
> 		}
> 
> 		public static string [] GetFileSystemEntries (string path, string pattern)
> 		{
> 			if (path == null)
> 				throw new ArgumentNullException ();
> 			if (path.IndexOfAny (Path.InvalidPathChars) != -1)
> 				throw new ArgumentException ("Path contains invalid characters");
> 			if (path == "")
> 				throw new ArgumentException ("The Path do not have a valid format");
> 
> 			return GetFileSystemEntries (path, pattern, 0, 0);
> 		}
> 		
> 		public static string[] GetLogicalDrives ()
> 		{ 
> 			//FIXME: Hardcoded Paths
> 			return new string [] { "A:\\", "C:\\" };
> 		}
> 
> 		public static DirectoryInfo GetParent (string path)
> 		{
> 			if (path == null)
> 				throw new ArgumentNullException ();
> 			if (path.IndexOfAny (Path.InvalidPathChars) != -1)
> 				throw new ArgumentException ("Path contains invalid characters");
> 			if (path == "")
> 				throw new ArgumentException ("The Path do not have a valid format");
> 			
> 			return new DirectoryInfo (Path.GetDirectoryName (path + Path.DirectorySeparatorChar + ".."));
> 		}
> 
> 		public static void Move (string src, string dest)
> 		{
> 			File.Move (src, dest);
> 		}
> 
> 		public static void SetCreationTime (string path, DateTime creation_time)
> 		{
> 			File.SetCreationTime (path, creation_time);
> 		}
> 		
> 		public static void SetCurrentDirectory (string path)
> 		{
> 			/*
> 			// Implementation complete 08/25/2001 14:24 except for
> 			// LAMESPEC: documentation specifies invalid exceptions IOException (i think)
> 			CheckArgument.Path (path, true);
> 			CheckPermission.Demand (FileIOPermissionAccess.Read & FileIOPermissionAccess.Write, path);	
> 			*/
> 			if (!Exists (path))
> 			{
> 				throw new DirectoryNotFoundException ("Directory \"" + path + "\" not found.");
> 			}
> 			Environment.CurrentDirectory = path;
> 		}
> 
> 		public static void SetLastAccessTime (string path, DateTime last_access_time)
> 		{
> 			File.SetLastAccessTime (path, last_access_time);
> 		}
> 		
> 		public static void SetLastWriteTime (string path, DateTime last_write_time)
> 		{
> 			File.SetLastWriteTime (path, last_write_time);
> 		}
> 		
> 		// private

Reply via email to