El mi�, 11-12-2002 a las 02:32, Gonzalo Paniagua Javier escribi�:
> I think that you should first commit the fixes and then, may be, the
> line ending change.
> 
> This way we all can see what has been fixed and how.

Fixed.

I changed the diff format to unified format too.

-- 
Eduardo Garcia Cebollero <[EMAIL PROTECTED]>
Index: ChangeLog
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System.IO/ChangeLog,v
retrieving revision 1.115
diff -u -d -r1.115 ChangeLog
--- ChangeLog	8 Dec 2002 04:31:33 -0000	1.115
+++ ChangeLog	11 Dec 2002 01:58:01 -0000
@@ -1,3 +1,14 @@
+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. Converted end-lines from dos-mode to unix-mode
+
+2002-12-08  Eduardo Garcia Cebollero <[EMAIL PROTECTED]>
+
+	* Directory.cs: CreateDirectory  works now with Absolute paths
+	too, not only with relative ones.
+
 2002-12-07  Peter Williams  <[EMAIL PROTECTED]>
 
 	* Directory.cs: Don't use the uninitialized pathsumm here.
Index: Directory.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System.IO/Directory.cs,v
retrieving revision 1.19
diff -u -d -r1.19 Directory.cs
--- Directory.cs	8 Dec 2002 04:31:33 -0000	1.19
+++ Directory.cs	11 Dec 2002 01:58:02 -0000
@@ -4,7 +4,8 @@
 // Authors:
 //   Jim Richardson  ([EMAIL PROTECTED])
 //   Miguel de Icaza ([EMAIL PROTECTED])
-//   Dan Lewis       ([EMAIL PROTECTED])
+//   Dan Lewis       ([EMAIL PROTECTED])
+//   Eduardo Garcia  ([EMAIL PROTECTED])
 //
 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
 // Copyright (C) 2002 Ximian, Inc.
@@ -18,15 +19,14 @@
 using System.Collections;
 using System.Text;
 
-namespace System.IO
-{
+namespace System.IO
+{
 	public sealed class Directory : Object
-	{
+	{
 		private Directory () {}
-
+		
 		public static DirectoryInfo CreateDirectory (string path)
 		{
-			StringBuilder pathsumm = new StringBuilder();
 			DirectoryInfo tmpinfo = null;
 			
 			if (path == null) {
@@ -40,27 +40,83 @@
 			if (path.IndexOfAny (Path.InvalidPathChars) != -1) {
 				throw new ArgumentException ("Path contains invalid chars");
 			}
-
+			
 			string[] pathcomponents = path.Split(new char[] { Path.DirectorySeparatorChar });
-
 			
-			if (pathcomponents.Length == 1) {
+			
+			if (pathcomponents.Length == 1){
 				tmpinfo = Directory.RealCreateDirectory(path);
 			} 
 			else {
-				foreach(string dir in pathcomponents)
+				if ((path[0]== Path.DirectorySeparatorChar) ||
+				    ((path[1] == ':') && (path[2] == Path.DirectorySeparatorChar))) //Absolute Path						
 				{
-					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");
+							}
 						}
+						
 					}
+					Directory.SetCurrentDirectory(actual_path);	
+				}
+				else //Relative Path
+				{
+					StringBuilder pathsumm = new StringBuilder();
 					
-					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());
+							}
+						}
 					}
 				}
 			}
@@ -111,9 +167,11 @@
 		}
 		
 		public static void Delete (string path, bool recurse)
-		{
+		{
 			if (path == null)
-				throw new ArgumentNullException ();
+				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");
 
@@ -128,7 +186,6 @@
 		public static bool Exists (string path)
 		{
 			MonoIOError error;
-			
 			return MonoIO.ExistsDirectory (path, out error);
 		}
 
@@ -169,10 +226,10 @@
 			return GetFileSystemEntries (path, pattern, FileAttributes.Directory, FileAttributes.Directory);
 		}
 		
-		public static string GetDirectoryRoot (string path)
-		{
-			return "" + Path.DirectorySeparatorChar;
-		}
+		public static string GetDirectoryRoot (string path)
+		{
+			return new String(Path.DirectorySeparatorChar,1);
+		}
 		
 		public static string [] GetFiles (string path)
 		{
@@ -185,29 +242,44 @@
 		}
 
 		public static string [] GetFileSystemEntries (string path)
-		{	
-			return GetFileSystemEntries (path, "*");
-		}
+		{
+			return GetFileSystemEntries (path, "*");
+		}
 
 		public static string [] GetFileSystemEntries (string path, string pattern)
-		{
-			return GetFileSystemEntries (path, pattern, 0, 0);
-		}
+		{
+			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 ()
-		{	
-			return new string [] { "A:\\", "C:\\" };
-		}
+		{ 
+			//FIXME: Hardcoded Paths
+			return new string [] { "A:\\", "C:\\" };
+		}
 
-		public static DirectoryInfo GetParent (string path)
-		{
-			return new DirectoryInfo (Path.GetDirectoryName (path));
-		}
+		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 Move (string src, string dest)
+		{
+			File.Move (src, dest);
+		}
 
 		public static void SetCreationTime (string path, DateTime creation_time)
 		{

Reply via email to