Selaa lähdekoodia

2004-06-21 Atsushi Enomoto <[email protected]>

	* FileStream.cs : Check buffer size before creating file.
	* StreamReader.cs : Check encoding!=null before creating file.
	* File.cs,
	  MonoIO.cs : Convert DateTime to FileTime after checking
	  file IO sharing violation (it just fixes the type of exception).

svn path=/trunk/mcs/; revision=30033
Atsushi Eno 21 vuotta sitten
vanhempi
sitoutus
5412643255

+ 8 - 0
mcs/class/corlib/System.IO/ChangeLog

@@ -1,3 +1,11 @@
+2004-06-21  Atsushi Enomoto  <[email protected]>
+
+	* FileStream.cs : Check buffer size before creating file.
+	* StreamReader.cs : Check encoding!=null before creating file.
+	* File.cs,
+	  MonoIO.cs : Convert DateTime to FileTime after checking
+	  file IO sharing violation (it just fixes the type of exception).
+
 2004-06-15  Gert Driesen <[email protected]>
 
 	* MemoryStream.cs: added TODO for serialization

+ 3 - 8
mcs/class/corlib/System.IO/File.cs

@@ -328,8 +328,7 @@ namespace System.IO
 			if (!MonoIO.Exists (path, out error))
 				throw MonoIO.GetException (path, error);
 			
-			if (!MonoIO.SetFileTime (path, creation_time.ToFileTime(),
-						 -1, -1, out error)) {
+			if (!MonoIO.SetCreationTime (path, creation_time, out error)) {
 				throw MonoIO.GetException (path, error);
 			}
 		}
@@ -347,9 +346,7 @@ namespace System.IO
 			if (!MonoIO.Exists (path, out error))
 				throw MonoIO.GetException (path, error);
 
-			if (!MonoIO.SetFileTime (path, -1,
-						 last_access_time.ToFileTime(), -1,
-						 out error)) {
+			if (!MonoIO.SetLastAccessTime (path, last_access_time, out error)) {
 				throw MonoIO.GetException (path, error);
 			}
 		}
@@ -367,9 +364,7 @@ namespace System.IO
 			if (!MonoIO.Exists (path, out error))
 				throw MonoIO.GetException (path, error);
 
-			if (!MonoIO.SetFileTime (path, -1, -1,
-						 last_write_time.ToFileTime(),
-						 out error)) {
+			if (!MonoIO.SetLastWriteTime (path, last_write_time, out error)) {
 				throw MonoIO.GetException (path, error);
 			}
 		}

+ 3 - 0
mcs/class/corlib/System.IO/FileStream.cs

@@ -121,6 +121,9 @@ namespace System.IO
 				throw new ArgumentException ("Name is empty");
 			}
 
+			if (bufferSize <= 0)
+				throw new ArgumentOutOfRangeException ("Positive number required.");
+
 			if (mode < FileMode.CreateNew || mode > FileMode.Append)
 				throw new ArgumentOutOfRangeException ("mode");
 

+ 50 - 0
mcs/class/corlib/System.IO/MonoIO.cs

@@ -241,6 +241,44 @@ namespace System.IO
 						long last_access_time,
 						long last_write_time,
 						out MonoIOError error)
+		{
+			return SetFileTime (path,
+				0,
+				creation_time,
+				last_access_time,
+				last_write_time,
+				DateTime.MinValue,
+				out error);
+		}
+
+		public static bool SetCreationTime (string path,
+						DateTime dateTime,
+						out MonoIOError error)
+		{
+			return SetFileTime (path, 1, -1, -1, -1, dateTime, out error);
+		}
+
+		public static bool SetLastAccessTime (string path,
+						DateTime dateTime,
+						out MonoIOError error)
+		{
+			return SetFileTime (path, 2, -1, -1, -1, dateTime, out error);
+		}
+
+		public static bool SetLastWriteTime (string path,
+						DateTime dateTime,
+						out MonoIOError error)
+		{
+			return SetFileTime (path, 3, -1, -1, -1, dateTime, out error);
+		}
+
+		public static bool SetFileTime (string path,
+						int type,
+						long creation_time,
+						long last_access_time,
+						long last_write_time,
+						DateTime dateTime,
+						out MonoIOError error)
 		{
 			IntPtr handle;
 			bool result;
@@ -251,6 +289,18 @@ namespace System.IO
 			if (handle == MonoIO.InvalidHandle)
 				return false;
 
+			switch (type) {
+			case 1:
+				creation_time = dateTime.ToFileTime ();
+				break;
+			case 2:
+				last_access_time = dateTime.ToFileTime ();
+				break;
+			case 3:
+				last_write_time = dateTime.ToFileTime ();
+				break;
+			}
+
 			result = SetFileTime (handle, creation_time,
 					      last_access_time,
 					      last_write_time, out error);

+ 2 - 0
mcs/class/corlib/System.IO/StreamReader.cs

@@ -155,6 +155,8 @@ namespace System.IO {
 				throw new ArgumentException("Empty path not allowed");
 			if (path.IndexOfAny (Path.InvalidPathChars) != -1)
 				throw new ArgumentException("path contains invalid characters");
+			if (null == encoding)
+				throw new ArgumentNullException ("encoding");
 			if (buffer_size <= 0)
 				throw new ArgumentOutOfRangeException ("buffer_size", "The minimum size of the buffer must be positive");