[Mono-list] [patch] a few fixes for System.IO.Directory

Eduardo Garcia Cebollero kiwnix@yahoo.es
11 Dec 2002 01:20:39 +0100


--=-Z5436Gx9k4XLW1dUGp5f
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

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 <kiwnix@yahoo.es>

--=-Z5436Gx9k4XLW1dUGp5f
Content-Disposition: attachment; filename=1.diff
Content-Type: text/x-patch; name=1.diff; charset=ISO-8859-15
Content-Transfer-Encoding: quoted-printable

Index: ChangeLog
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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 <kiwnix@yahoo.es>
>=20
> 	*Directory.cs: Some Exceptions added, fixed GetParent(),
> 	CreateDirectory() should work with unix, native windows and
> 	windows samba shares.
>=20
> 2002-12-08  Eduardo Garcia Cebollero <kiwnix@yahoo.es>
>=20
> 	* Directory.cs: CreateDirectory  works now with Absolute paths
> 	too, not only with relative ones.
>=20
Index: Directory.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/mcs/class/corlib/System.IO/Directory.cs,v
retrieving revision 1.19
diff -r1.19 Directory.cs
1,17c1,18
< //=20
< // System.IO.Directory.cs=20
< //
< // Authors:
< //   Jim Richardson  (develop@wtfo-guru.com)
< //   Miguel de Icaza (miguel@ximian.com)
< //   Dan Lewis       (dihlewis@yahoo.co.uk)
< //
< // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
< // Copyright (C) 2002 Ximian, Inc.
< //=20
< // Created:        Monday, August 13, 2001=20
< //
< //-----------------------------------------------------------------------=
-------
<=20
< using System;
< using System.Security.Permissions;
---
> //=20
> // System.IO.Directory.cs=20
> //
> // Authors:
> //   Jim Richardson  (develop@wtfo-guru.com)
> //   Miguel de Icaza (miguel@ximian.com)
> //   Dan Lewis       (dihlewis@yahoo.co.uk)
> //   Eduardo Garcia  (kiwnix@yahoo.es)
> //
> // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
> // Copyright (C) 2002 Ximian, Inc.
> //=20
> // Created:        Monday, August 13, 2001=20
> //
> //-----------------------------------------------------------------------=
-------
>=20
> using System;
> using System.Security.Permissions;
20,25d20
<=20
< namespace System.IO
< {
< 	public sealed class Directory : Object
< 	{
< 		private Directory () {}
26a22,27
> namespace System.IO
> {
> 	public sealed class Directory : Object
> 	{
> 		private Directory () {}
> 	=09
29d29
< 			StringBuilder pathsumm =3D new StringBuilder();
43c43
<=20
---
> 		=09
45d44
<=20
47c46,47
< 			if (pathcomponents.Length =3D=3D 1) {
---
> 		=09
> 			if (pathcomponents.Length =3D=3D 1){
51c51,52
< 				foreach(string dir in pathcomponents)
---
> 				if ((path[0]=3D=3D Path.DirectorySeparatorChar) ||
> 				    ((path[1] =3D=3D ':') && (path[2] =3D=3D Path.DirectorySeparatorC=
har))) //Absolute Path					=09
53,58c54,96
< 					if (dir.Length !=3D 0) {
< 						if (pathsumm.Length =3D=3D 0) {
< 							pathsumm.Append(dir);
< 						}=20
< 						else {
< 							pathsumm.Append(Path.DirectorySeparatorChar + dir);
---
> 					//Should Work in Unix, Win* native Directoryes and Samba Shares
> 					//FIXME: This is not thread safe
> 				   =20
> 				=09
> 					string actual_path =3D Directory.GetCurrentDirectory();
> 				=09
> 					if (Environment.OSVersion.Platform =3D=3D PlatformID.Unix) //Is Unix
> 					{
> 						StringBuilder pathsumm =3D new StringBuilder(path);
> 						Directory.SetCurrentDirectory("/");
> 						pathsumm.Remove(0,1);
> 						tmpinfo =3D Directory.CreateDirectory(pathsumm.ToString());
> 					}
> 					else //We asume is Win*
> 					{
> 						if ((path[1] =3D=3D ':') || (path[0] =3D=3D Path.DirectorySeparator=
Char)) //Is a regular path
> 						{
> 							StringBuilder pathsumm =3D new StringBuilder(path);
> 							Directory.SetCurrentDirectory(path.Substring(0,2));
> 							pathsumm.Remove(0,2);
> 							tmpinfo =3D Directory.CreateDirectory(pathsumm.ToString());						=09
> 						}							=09
> 						else if((path[0] =3D=3D '\\') && (path[1] =3D=3D '\\')) //Is a Samb=
a Share
> 						{
> 							if (Directory.Exists(pathcomponents[0] + "\\"
> 									     + pathcomponents[1] + "\\"
> 									     + pathcomponents[2]))
> 							{
> 								StringBuilder pathsumm =3D new StringBuilder();=09
> 								Directory.SetCurrentDirectory(pathcomponents[0] +=20
> 											      "\\" + pathcomponents[1] +
> 											      "\\" + pathcomponents[2]);
> 								pathcomponents[0] =3D ""; pathcomponents[1] =3D ""; pathcomponent=
s[2] =3D "";
> 								foreach(string dir in pathsumm.ToString())
> 								{
> 									pathsumm.Append(dir + "\\");
> 								}	=09
> 								Directory.CreateDirectory(pathsumm.ToString());
> 							}
> 							else
> 							{
> 								throw new DirectoryNotFoundException("The samba share do not Exis=
ts");
> 							}
59a98
> 					=09
60a100,104
> 					Directory.SetCurrentDirectory(actual_path);=09
> 				}
> 				else //Relative Path
> 				{
> 					StringBuilder pathsumm =3D new StringBuilder();
62,63c106,119
< 					if (pathsumm.Length !=3D 0 && !Directory.Exists (pathsumm.ToString()=
)) {
< 						tmpinfo =3D Directory.RealCreateDirectory (pathsumm.ToString());
---
> 					foreach(string dir in pathcomponents)
> 					{
> 						if (dir.Length !=3D 0) {
> 							if (pathsumm.Length =3D=3D 0) {
> 								pathsumm.Append (dir);
> 							}=20
> 							else {
> 								pathsumm.Append (Path.DirectorySeparatorChar + dir);
> 							}
> 						=09
> 							if (!Directory.Exists (pathsumm.ToString())) {
> 								tmpinfo =3D Directory.RealCreateDirectory (pathsumm.ToString());
> 							}
> 						}
102,126c158,184
< 		static void RecursiveDelete (string path)
< 		{
< 			foreach (string dir in GetDirectories (path))
< 				RecursiveDelete (dir);
<=20
< 			foreach (string file in GetFiles (path))
< 				File.Delete (file);
<=20
< 			Directory.Delete (path);
< 		}
< 	=09
< 		public static void Delete (string path, bool recurse)
< 		{
< 			if (path =3D=3D null)
< 				throw new ArgumentNullException ();
< 			if (path.IndexOfAny (Path.InvalidPathChars) !=3D -1)
< 				throw new ArgumentException ("Path contains invalid characters");
<=20
< 			if (recurse =3D=3D false){
< 				Delete (path);
< 				return;
< 			}
<=20
< 			RecursiveDelete (path);
< 		}
---
> 		static void RecursiveDelete (string path)
> 		{
> 			foreach (string dir in GetDirectories (path))
> 				RecursiveDelete (dir);
>=20
> 			foreach (string file in GetFiles (path))
> 				File.Delete (file);
>=20
> 			Directory.Delete (path);
> 		}
> 	=09
> 		public static void Delete (string path, bool recurse)
> 		{
> 			if (path =3D=3D null)
> 				throw new ArgumentNullException ();
> 			if (path =3D=3D "")
> 				throw new System.ArgumentException("Path is Empty");
> 			if (path.IndexOfAny (Path.InvalidPathChars) !=3D -1)
> 				throw new ArgumentException ("Path contains invalid characters");
>=20
> 			if (recurse =3D=3D false){
> 				Delete (path);
> 				return;
> 			}
>=20
> 			RecursiveDelete (path);
> 		}
131d188
< 		=09
135,242c192,314
< 		public static DateTime GetLastAccessTime (string path)
< 		{
< 			return File.GetLastAccessTime (path);
< 		}
< 	=09
< 		public static DateTime GetLastWriteTime (string path)
< 		{
< 			return File.GetLastWriteTime (path);
< 		}
< 	=09
< 		public static DateTime GetCreationTime (string path)
< 		{
< 			return File.GetLastWriteTime (path);
< 		}
< 	=09
< 		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 =3D Environment.CurrentDirectory;
< 			CheckPermission.Demand (FileIOPermissionAccess.Read & FileIOPermission=
Access.Write, str);
< 			*/
< 			return Environment.CurrentDirectory;
< 		}
< 	=09
< 		public static string [] GetDirectories (string path)
< 		{
< 			return GetDirectories (path, "*");
< 		}
< 	=09
< 		public static string [] GetDirectories (string path, string pattern)
< 		{
< 			return GetFileSystemEntries (path, pattern, FileAttributes.Directory, =
FileAttributes.Directory);
< 		}
< 	=09
< 		public static string GetDirectoryRoot (string path)
< 		{
< 			return "" + Path.DirectorySeparatorChar;
< 		}
< 	=09
< 		public static string [] GetFiles (string path)
< 		{
< 			return GetFiles (path, "*");
< 		}
< 	=09
< 		public static string [] GetFiles (string path, string pattern)
< 		{
< 			return GetFileSystemEntries (path, pattern, FileAttributes.Directory, =
0);
< 		}
<=20
< 		public static string [] GetFileSystemEntries (string path)
< 		{=09
< 			return GetFileSystemEntries (path, "*");
< 		}
<=20
< 		public static string [] GetFileSystemEntries (string path, string patte=
rn)
< 		{
< 			return GetFileSystemEntries (path, pattern, 0, 0);
< 		}
< 	=09
< 		public static string[] GetLogicalDrives ()
< 		{=09
< 			return new string [] { "A:\\", "C:\\" };
< 		}
<=20
< 		public static DirectoryInfo GetParent (string path)
< 		{
< 			return new DirectoryInfo (Path.GetDirectoryName (path));
< 		}
<=20
< 		public static void Move (string src, string dest)
< 		{
< 			File.Move (src, dest);
< 		}
<=20
< 		public static void SetCreationTime (string path, DateTime creation_time=
)
< 		{
< 			File.SetCreationTime (path, creation_time);
< 		}
< 	=09
< 		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 & FileIOPermission=
Access.Write, path);=09
< 			*/
< 			if (!Exists (path))
< 			{
< 				throw new DirectoryNotFoundException ("Directory \"" + path + "\" not=
 found.");
< 			}
< 			Environment.CurrentDirectory =3D path;
< 		}
<=20
< 		public static void SetLastAccessTime (string path, DateTime last_access=
_time)
< 		{
< 			File.SetLastAccessTime (path, last_access_time);
< 		}
< 	=09
< 		public static void SetLastWriteTime (string path, DateTime last_write_t=
ime)
< 		{
< 			File.SetLastWriteTime (path, last_write_time);
< 		}
< 	=09
< 		// private
---
> 		public static DateTime GetLastAccessTime (string path)
> 		{
> 			return File.GetLastAccessTime (path);
> 		}
> 	=09
> 		public static DateTime GetLastWriteTime (string path)
> 		{
> 			return File.GetLastWriteTime (path);
> 		}
> 	=09
> 		public static DateTime GetCreationTime (string path)
> 		{
> 			return File.GetLastWriteTime (path);
> 		}
> 	=09
> 		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 =3D Environment.CurrentDirectory;
> 			CheckPermission.Demand (FileIOPermissionAccess.Read & FileIOPermission=
Access.Write, str);
> 			*/
> 			return Environment.CurrentDirectory;
> 		}
> 	=09
> 		public static string [] GetDirectories (string path)
> 		{
> 			return GetDirectories (path, "*");
> 		}
> 	=09
> 		public static string [] GetDirectories (string path, string pattern)
> 		{
> 			return GetFileSystemEntries (path, pattern, FileAttributes.Directory, =
FileAttributes.Directory);
> 		}
> 	=09
> 		public static string GetDirectoryRoot (string path)
> 		{
> 			return new String(Path.DirectorySeparatorChar,1);
> 		}
> 	=09
> 		public static string [] GetFiles (string path)
> 		{
> 			return GetFiles (path, "*");
> 		}
> 	=09
> 		public static string [] GetFiles (string path, string pattern)
> 		{
> 			return GetFileSystemEntries (path, pattern, FileAttributes.Directory, =
0);
> 		}
>=20
> 		public static string [] GetFileSystemEntries (string path)
> 		{
> 			return GetFileSystemEntries (path, "*");
> 		}
>=20
> 		public static string [] GetFileSystemEntries (string path, string patte=
rn)
> 		{
> 			if (path =3D=3D null)
> 				throw new ArgumentNullException ();
> 			if (path.IndexOfAny (Path.InvalidPathChars) !=3D -1)
> 				throw new ArgumentException ("Path contains invalid characters");
> 			if (path =3D=3D "")
> 				throw new ArgumentException ("The Path do not have a valid format");
>=20
> 			return GetFileSystemEntries (path, pattern, 0, 0);
> 		}
> 	=09
> 		public static string[] GetLogicalDrives ()
> 		{=20
> 			//FIXME: Hardcoded Paths
> 			return new string [] { "A:\\", "C:\\" };
> 		}
>=20
> 		public static DirectoryInfo GetParent (string path)
> 		{
> 			if (path =3D=3D null)
> 				throw new ArgumentNullException ();
> 			if (path.IndexOfAny (Path.InvalidPathChars) !=3D -1)
> 				throw new ArgumentException ("Path contains invalid characters");
> 			if (path =3D=3D "")
> 				throw new ArgumentException ("The Path do not have a valid format");
> 		=09
> 			return new DirectoryInfo (Path.GetDirectoryName (path + Path.Directory=
SeparatorChar + ".."));
> 		}
>=20
> 		public static void Move (string src, string dest)
> 		{
> 			File.Move (src, dest);
> 		}
>=20
> 		public static void SetCreationTime (string path, DateTime creation_time=
)
> 		{
> 			File.SetCreationTime (path, creation_time);
> 		}
> 	=09
> 		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 & FileIOPermission=
Access.Write, path);=09
> 			*/
> 			if (!Exists (path))
> 			{
> 				throw new DirectoryNotFoundException ("Directory \"" + path + "\" not=
 found.");
> 			}
> 			Environment.CurrentDirectory =3D path;
> 		}
>=20
> 		public static void SetLastAccessTime (string path, DateTime last_access=
_time)
> 		{
> 			File.SetLastAccessTime (path, last_access_time);
> 		}
> 	=09
> 		public static void SetLastWriteTime (string path, DateTime last_write_t=
ime)
> 		{
> 			File.SetLastWriteTime (path, last_write_time);
> 		}
> 	=09
> 		// private

--=-Z5436Gx9k4XLW1dUGp5f--