2009-11-03 Miguel de Icaza <miguel@novell.com>
authorMiguel de Icaza <miguel@gnome.org>
Tue, 3 Nov 2009 05:34:06 +0000 (05:34 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Tue, 3 Nov 2009 05:34:06 +0000 (05:34 -0000)
* FileStream.cs: Check the return value of MonoIO.Write and handle
short-writes as those can happen when a FileStream is used on top
of a pipe on Unix.

Fixes bug: #531613, this should be backported to 2-4 and 2-6 after
some testing.

svn path=/trunk/mcs/; revision=145271

mcs/class/corlib/System.IO/ChangeLog
mcs/class/corlib/System.IO/FileStream.cs

index fa9e5dd4769ec228b4b73af050eddb60a76665f6..d70a3fb749f45ebeaaf282061c391eca3c19b297 100644 (file)
@@ -1,3 +1,12 @@
+2009-11-03  Miguel de Icaza  <miguel@novell.com>
+
+       * FileStream.cs: Check the return value of MonoIO.Write and handle
+       short-writes as those can happen when a FileStream is used on top
+       of a pipe on Unix.
+
+       Fixes bug: #531613, this should be backported to 2-4 and 2-6 after
+       some testing.
+
 2009-10-29  Sebastien Pouliot  <sebastien@ximian.com>
 
        * FileStream.cs: Reduce code duplication by merging FillBuffer 
index f5c17bbe8ac6d042ef03d3e2690e71577ce3e841..17cd3c6c73128787b0be69c2e9186e90cae332af 100644 (file)
@@ -644,13 +644,16 @@ namespace System.IO
                                MonoIOError error;
 
                                FlushBuffer ();
-
-                               MonoIO.Write (handle, src, offset, count, out error);
-                               if (error != MonoIOError.ERROR_SUCCESS) {
-                                       // don't leak the path information for isolated storage
-                                       throw MonoIO.GetException (GetSecureFileName (name), error);
-                               }
+                               int wcount = count;
                                
+                               while (wcount > 0){
+                                       int n = MonoIO.Write (handle, src, offset, wcount, out error);
+                                       if (error != MonoIOError.ERROR_SUCCESS)
+                                               throw MonoIO.GetException (GetSecureFileName (name), error);
+                                       
+                                       wcount -= n;
+                                       offset += n;
+                               } 
                                buf_start += count;
                        } else {
 
@@ -985,12 +988,16 @@ namespace System.IO
                                        }
                                }
                                if (st == null) {
-                                       MonoIO.Write (handle, buf, 0,
-                                                     buf_length, out error);
-
-                                       if (error != MonoIOError.ERROR_SUCCESS) {
-                                               // don't leak the path information for isolated storage
-                                               throw MonoIO.GetException (GetSecureFileName (name), error);
+                                       int wcount = buf_length;
+                                       int offset = 0;
+                                       while (wcount > 0){
+                                               int n = MonoIO.Write (handle, buf, 0, buf_length, out error);
+                                               if (error != MonoIOError.ERROR_SUCCESS) {
+                                                       // don't leak the path information for isolated storage
+                                                       throw MonoIO.GetException (GetSecureFileName (name), error);
+                                               }
+                                               wcount -= n;
+                                               offset += n;
                                        }
                                } else {
                                        st.Write (buf, 0, buf_length);