[Mono-bugs] [Bug 71292][Nor] New - File locking files

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 14 Jan 2005 17:52:54 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by miguel@ximian.com.

http://bugzilla.ximian.com/show_bug.cgi?id=71292

--- shadow/71292	2005-01-14 17:52:54.000000000 -0500
+++ shadow/71292.tmp.12735	2005-01-14 17:52:54.000000000 -0500
@@ -0,0 +1,66 @@
+Bug#: 71292
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: miguel@ximian.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: File locking files
+
+FRom our NUnit tests comes this program, it should not print
+anythign:
+
+using System.Globalization;
+using System;
+using System.IO;
+
+class X {
+	static void AssertEquals (string msg, Type a, Type b)
+	{
+		if (a != b)
+			Console.WriteLine ("Test {0} fails", msg);
+	}
+	
+	static readonly string tmpPath = Path.GetTempPath ();
+	
+	static void Main ()
+	{
+			string path = "TestLock";
+                	File.Delete (path);
+
+                	FileStream stream = new FileStream (path,
+FileMode.CreateNew, FileAccess.ReadWrite);
+                	                	
+	               	stream.Write (new Byte [] {0,1,2,3,4,5,6,7,8,9,10}, 0,
+10);                              	
+                	stream.Close ();
+
+                	stream = new FileStream (path, FileMode.Open,
+FileAccess.ReadWrite);
+                	
+                	stream.Lock (0, 5);
+                	
+                	FileStream stream2 = new FileStream (path , FileMode.Open,
+FileAccess.Read, FileShare.ReadWrite);
+                	
+                	byte [] bytes = new byte [5];
+                	try {                		
+                		stream2.Read (bytes, 0, 5);
+				Console.WriteLine ("Failed, should have thrown an exception");
+                	} catch (Exception e) {
+                		
+                		// locked
+                		AssertEquals ("test#01", typeof (IOException), e.GetType ());
+                	}
+               		                
+	}
+}