Fix problems with overlong directory names: phase #1
[mono.git] / mcs / class / Mono.Posix / Mono.Unix / UnixStream.cs
index 72628370c2a0b0c676ce6740bd783aee4ed8f789..64795781531b8325ed254853ce3e1351b9599e31 100644 (file)
@@ -176,6 +176,7 @@ namespace Mono.Unix {
 
                private void RefreshStat ()
                {
+                       AssertNotDisposed ();
                        int r = Native.Syscall.fstat (fileDescriptor, out stat);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                }
@@ -192,24 +193,6 @@ namespace Mono.Unix {
 
                public override void Flush ()
                {
-                       int r = Native.Syscall.fsync (fileDescriptor);
-
-                       if (r == -1) {
-                               Native.Errno e = Native.Stdlib.GetLastError ();
-
-                               // From the man page:
-                               //  EROFS, EINVAL:
-                               //    fd is bound to a special file which does not support
-                               //    synchronization.
-                               // Sockets are such a file, and since Close() calls Flush(), and we
-                               // want to support manually opened sockets, we shouldn't generate an
-                               // exception for these errors.
-                               if (e == Native.Errno.EROFS || e == Native.Errno.EINVAL) {
-                                       return;
-                               }
-
-                               UnixMarshal.ThrowExceptionForError (e);
-                       }
                }
 
                public override unsafe int Read ([In, Out] byte[] buffer, int offset, int count)
@@ -407,6 +390,10 @@ namespace Mono.Unix {
                                return;
                                
                        Flush ();
+
+                       if (!owner)
+                               return;
+
                        int r;
                        do {
                                r = Native.Syscall.close (fileDescriptor);