Fix problems with overlong directory names: phase #1
[mono.git] / mcs / class / Mono.Posix / Mono.Unix / UnixFileInfo.cs
index 5a12445768f93657fb92056610337c037c1bf0d8..48248c14312bd2d4cde1204e0a1d45450039af80 100644 (file)
@@ -4,7 +4,7 @@
 // Authors:
 //   Jonathan Pryor (jonpryor@vt.edu)
 //
-// (C) 2004 Jonathan Pryor
+// (C) 2004-2006 Jonathan Pryor
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -40,7 +40,7 @@ namespace Mono.Unix {
                {
                }
 
-               internal UnixFileInfo (string path, Stat stat)
+               internal UnixFileInfo (string path, Native.Stat stat)
                        : base (path, stat)
                {
                }
@@ -59,39 +59,52 @@ namespace Mono.Unix {
 
                public override void Delete ()
                {
-                       int r = Syscall.unlink (FullPath);
+                       int r = Native.Syscall.unlink (FullPath);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                        base.Refresh ();
                }
 
                public UnixStream Create ()
                {
-                       FilePermissions mode = // 0644
-                               FilePermissions.S_IRUSR | FilePermissions.S_IWUSR |
-                               FilePermissions.S_IRGRP | FilePermissions.S_IROTH; 
+                       Native.FilePermissions mode = // 0644
+                               Native.FilePermissions.S_IRUSR | Native.FilePermissions.S_IWUSR |
+                               Native.FilePermissions.S_IRGRP | Native.FilePermissions.S_IROTH; 
                        return Create (mode);
                }
 
-               public UnixStream Create (FilePermissions mode)
+               [CLSCompliant (false)]
+               public UnixStream Create (Native.FilePermissions mode)
                {
-                       int fd = Syscall.creat (FullPath, mode);
+                       int fd = Native.Syscall.creat (FullPath, mode);
                        if (fd < 0)
                                UnixMarshal.ThrowExceptionForLastError ();
                        base.Refresh ();
                        return new UnixStream (fd);
                }
 
-               public UnixStream Open (OpenFlags flags)
+               public UnixStream Create (FileAccessPermissions mode)
                {
-                       int fd = Syscall.open (FullPath, flags);
+                       return Create ((Native.FilePermissions) mode);
+               }
+
+               [CLSCompliant (false)]
+               public UnixStream Open (Native.OpenFlags flags)
+               {
+                       if ((flags & Native.OpenFlags.O_CREAT) != 0)
+                               throw new ArgumentException (
+                                               "Cannot specify OpenFlags.O_CREAT without providing " + 
+                                               "FilePermissions.  Use the Open(OpenFlags, FilePermissions) " +
+                                               "method instead");
+                       int fd = Native.Syscall.open (FullPath, flags);
                        if (fd < 0)
                                UnixMarshal.ThrowExceptionForLastError ();
                        return new UnixStream (fd);
                }
 
-               public UnixStream Open (OpenFlags flags, FilePermissions mode)
+               [CLSCompliant (false)]
+               public UnixStream Open (Native.OpenFlags flags, Native.FilePermissions mode)
                {
-                       int fd = Syscall.open (FullPath, flags, mode);
+                       int fd = Native.Syscall.open (FullPath, flags, mode);
                        if (fd < 0)
                                UnixMarshal.ThrowExceptionForLastError ();
                        return new UnixStream (fd);
@@ -99,26 +112,21 @@ namespace Mono.Unix {
 
                public UnixStream Open (FileMode mode)
                {
-                       OpenFlags flags = UnixConvert.ToOpenFlags (mode, FileAccess.ReadWrite);
-                       int fd = Syscall.open (FullPath, flags);
-                       if (fd < 0)
-                               UnixMarshal.ThrowExceptionForLastError ();
-                       return new UnixStream (fd);
+                       Native.OpenFlags flags = Native.NativeConvert.ToOpenFlags (mode, FileAccess.ReadWrite);
+                       return Open (flags);
                }
 
                public UnixStream Open (FileMode mode, FileAccess access)
                {
-                       OpenFlags flags = UnixConvert.ToOpenFlags (mode, access);
-                       int fd = Syscall.open (FullPath, flags);
-                       if (fd < 0)
-                               UnixMarshal.ThrowExceptionForLastError ();
-                       return new UnixStream (fd);
+                       Native.OpenFlags flags = Native.NativeConvert.ToOpenFlags (mode, access);
+                       return Open (flags);
                }
 
-               public UnixStream Open (FileMode mode, FileAccess access, FilePermissions perms)
+               [CLSCompliant (false)]
+               public UnixStream Open (FileMode mode, FileAccess access, Native.FilePermissions perms)
                {
-                       OpenFlags flags = UnixConvert.ToOpenFlags (mode, access);
-                       int fd = Syscall.open (FullPath, flags, perms);
+                       Native.OpenFlags flags = Native.NativeConvert.ToOpenFlags (mode, access);
+                       int fd = Native.Syscall.open (FullPath, flags, perms);
                        if (fd < 0)
                                UnixMarshal.ThrowExceptionForLastError ();
                        return new UnixStream (fd);