[Mono-bugs] [Bug 77423][Nor] New - Locked file can be wiped out by
a StreamWriter
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Tue Jan 31 15:53:43 EST 2006
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 lluis at ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=77423
--- shadow/77423 2006-01-31 15:53:43.000000000 -0500
+++ shadow/77423.tmp.17555 2006-01-31 15:53:43.000000000 -0500
@@ -0,0 +1,61 @@
+Bug#: 77423
+Product: Mono: Runtime
+Version: 1.1
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: io-layer
+AssignedTo: dick at ximian.com
+ReportedBy: lluis at ximian.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Locked file can be wiped out by a StreamWriter
+
+The following test case opens a file with FileShare.None access, so in
+theory it can't be modified by another writer. However, when a StreamWriter
+tries to rewrite the file, although it fails with an exception, the file is
+wiped out.
+
+using System;
+using System.IO;
+using System.Threading;
+
+public class Test
+{
+ static string TheFile = "/tmp/somefile.txt";
+
+ public static void Main (string[] args)
+ {
+ // Write some file
+ StreamWriter sw = new StreamWriter (TheFile);
+ sw.WriteLine ("Hello!");
+ sw.Close ();
+
+ // Open and lock the file
+ FileStream s = File.Open (TheFile, FileMode.Open, FileAccess.Read,
+FileShare.None);
+
+ // Try to modify the locked file
+ try {
+ StreamWriter w = new StreamWriter (TheFile, false);
+ w.Write ("Bye!");
+ w.Close ();
+ } catch {
+ Console.WriteLine ("File was locked!");
+ }
+
+ s.Close ();
+
+ // Show the contents
+ StreamReader sr = new StreamReader (TheFile);
+ Console.WriteLine ("Contents: " + sr.ReadToEnd ());
+ sr.Close ();
+
+ File.Delete (TheFile);
+ }
+}
More information about the mono-bugs
mailing list