[Mono-bugs] [Bug 319901] FileStream's position gets changed by implicit and explicit flushing

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Mar 24 21:00:05 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=319901

https://bugzilla.novell.com/show_bug.cgi?id=319901#c1


Miguel de Icaza <miguel at novell.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |miguel at novell.com
         Resolution|                            |FIXED

--- Comment #1 from Miguel de Icaza <miguel at novell.com> 2011-03-25 01:00:03 UTC ---
I am unable to reproduce this problem, here is the self-contained test case I
am using:


using System.IO;
using System;

class X {
    static void Main ()
    {
        using (var fs = new FileStream
("/tmp/TestSetPositionImplicitFlushProblem.dat",
                        FileMode.Create,
                        FileAccess.ReadWrite,
                        FileShare.None,
                        8192))
        {
            byte[] buffer1 = new byte[100];
            byte[] buffer2 = new byte[buffer1.Length];

            for (int index = 0; (index < buffer1.Length); index++)
                buffer1[index] = (byte)(index & 0xff);

            fs.Write(buffer1, 0, buffer1.Length);
            fs.Position = 0;

            AreEqual(fs.Length, 100);    // Implicit flushing
            fs.Flush ();
            AreEqual(fs.Position, 0);
            AreEqual(fs.Read(buffer2, 0, buffer2.Length), buffer2.Length);

            for (int i = 0; i < 100; i++)
                if (buffer1 [i] != buffer2 [i])
                    throw new Exception ();
            AreEqual(buffer1, buffer2);
        }
        using (FileStream fs = new FileStream
("/tmp/TestPositionAfterExplicitFlushProblem.dat",
                               FileMode.Create,
                               FileAccess.ReadWrite,
                               FileShare.None,
                               8192))
        {
            byte[] buffer1 = new byte[100];
            byte[] buffer2 = new byte[buffer1.Length];

            for (int index = 0; (index < buffer1.Length); index++)
                buffer1[index] = (byte)(index & 0xff);

            fs.Write(buffer1, 0, buffer1.Length);
            fs.Position = 0;

            fs.Flush();                            // Explicit flushing

            AreEqual(fs.Position, 0);
            AreEqual(fs.Read(buffer2, 0, buffer2.Length), buffer2.Length);
            AreEqual(buffer1, buffer2);
            for (int i = 0; i < 100; i++)
                if (buffer1 [i] != buffer2 [i])
                    throw new Exception ();
        }
    }

    public static void AreEqual (object a, object b)
    {
        Console.WriteLine ("{0} == {1}", a, b);
    }
}

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list