* Mono.Unix/FileTypes.cs: Remove [Flags] attribute -- these aren't bitfield
authorJonathan Pryor <jpryor@novell.com>
Mon, 9 Jan 2006 18:43:14 +0000 (18:43 -0000)
committerJonathan Pryor <jpryor@novell.com>
Mon, 9 Jan 2006 18:43:14 +0000 (18:43 -0000)
  values.
  * Mono.Unix/UnixFileSystemInfo.cs: Fix Is<<Type>> properties -- before it
  would erroneously say that a symlink was a character device.  (This is
  because device values are *not* [Flags] values, but code was assuming they
  were.)
  * Mono.Unix/UnixGroupInfo.cs: Clone the string[] returned from
  GetMemberNames().  We don't want callers to change the underlying list.

  * Mono.Unix.Native/NativeConvert.cs: s/IsType/IsSet/g: deal with
  UnixFileSystemInfo method name change.

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

mcs/class/Mono.Posix/Mono.Unix.Native/ChangeLog
mcs/class/Mono.Posix/Mono.Unix.Native/NativeConvert.cs
mcs/class/Mono.Posix/Mono.Unix/ChangeLog
mcs/class/Mono.Posix/Mono.Unix/FileTypes.cs
mcs/class/Mono.Posix/Mono.Unix/UnixFileSystemInfo.cs
mcs/class/Mono.Posix/Mono.Unix/UnixGroupInfo.cs

index 5a6db9403b4e15cad8bfd051c8fa71ac62420583..5c8e0be178897824444d0a16bae9912219ea5b19 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-09  Jonathan Pryor <jonpryor@vt.edu>
+
+       * NativeConvert.cs: s/IsType/IsSet/g: deal with UnixFileSystemInfo method 
+         name change.
+
 2005-01-02  Jonathan Pryor <jonpryor@vt.edu>
 
        * Stdlib.cs: s/ACCESS/ACCES/g.  I didn't create a badly named errno value, I
index 8076676b795114ddcaede6575deb4536b0ff9032..cc9c13717889468c3127b73d05babcc6a0a2ef84 100644 (file)
@@ -141,9 +141,9 @@ namespace Mono.Unix.Native {
                        FilePermissions read, FilePermissions write, FilePermissions exec,
                        char both, char setonly, FilePermissions setxbit)
                {
-                       if (UnixFileSystemInfo.IsType (value, read))
+                       if (UnixFileSystemInfo.IsSet (value, read))
                                access [index] = 'r';
-                       if (UnixFileSystemInfo.IsType (value, write))
+                       if (UnixFileSystemInfo.IsSet (value, write))
                                access [index+1] = 'w';
                        access [index+2] = GetSymbolicMode (value, exec, both, setonly, setxbit);
                }
@@ -153,8 +153,8 @@ namespace Mono.Unix.Native {
                private static char GetSymbolicMode (FilePermissions value, 
                        FilePermissions xbit, char both, char setonly, FilePermissions setxbit)
                {
-                       bool is_x  = UnixFileSystemInfo.IsType (value, xbit);
-                       bool is_sx = UnixFileSystemInfo.IsType (value, setxbit);
+                       bool is_x  = UnixFileSystemInfo.IsSet (value, xbit);
+                       bool is_sx = UnixFileSystemInfo.IsSet (value, setxbit);
                        
                        if (is_x && is_sx)
                                return both;
index 3fd6008e6e9893d6e09b33ed4fbb7864629caaf3..98ac8aba077a4bc13081de33c2cd4fb763d96788 100644 (file)
@@ -1,3 +1,12 @@
+2006-01-09  Jonathan Pryor <jonpryor@vt.edu>
+
+       * FileTypes.cs: Remove [Flags] attribute -- these aren't bitfield values.
+       * UnixFileSystemInfo.cs: Fix Is<<Type>> properties -- before it would
+         erroneously say that a symlink was a character device.  (This is because
+         device values are *not* [Flags] values, but code was assuming they were.)
+       * UnixGroupInfo.cs: Clone the string[] returned from GetMemberNames().  We
+         don't want callers to change the underlying list.
+
 2006-01-07  Jonathan Pryor <jonpryor@vt.edu>
 
        * UnixMarshal.cs: *Actually* put things in alphabetical order (like the
index 3e47a7dcb92e5b1ad409f001ca3474192acaaea2..0059705dce5e6e7f38d42fa08f71ed8522aeca2a 100644 (file)
@@ -31,7 +31,6 @@ using Mono.Unix;
 
 namespace Mono.Unix {
 
-       [Flags]
        public enum FileTypes {
                Directory         = (int) Native.FilePermissions.S_IFDIR,
                CharacterDevice   = (int) Native.FilePermissions.S_IFCHR,
index 903afebabdfc727a94c136bba5a4f67d45755881..34a0139c38b50afa8544ac83052ab84733e6adfe 100644 (file)
@@ -120,8 +120,7 @@ namespace Mono.Unix {
                public FileTypes FileType {
                        get {
                                AssertValid ();
-                               int type = (int) stat.st_mode;
-                               return (FileTypes) (type & (int) AllFileTypes);
+                               return (FileTypes) (stat.st_mode & Native.FilePermissions.S_IFMT);
                        }
                        // no set as chmod(2) won't accept changing the file type.
                }
@@ -217,46 +216,51 @@ namespace Mono.Unix {
                }
 
                public bool IsDirectory {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_IFDIR);}
+                       get {AssertValid (); return IsFileType (stat.st_mode, Native.FilePermissions.S_IFDIR);}
                }
 
                public bool IsCharacterDevice {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_IFCHR);}
+                       get {AssertValid (); return IsFileType (stat.st_mode, Native.FilePermissions.S_IFCHR);}
                }
 
                public bool IsBlockDevice {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_IFBLK);}
+                       get {AssertValid (); return IsFileType (stat.st_mode, Native.FilePermissions.S_IFBLK);}
                }
 
                public bool IsRegularFile {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_IFREG);}
+                       get {AssertValid (); return IsFileType (stat.st_mode, Native.FilePermissions.S_IFREG);}
                }
 
                public bool IsFifo {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_IFIFO);}
+                       get {AssertValid (); return IsFileType (stat.st_mode, Native.FilePermissions.S_IFIFO);}
                }
 
                public bool IsSymbolicLink {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_IFLNK);}
+                       get {AssertValid (); return IsFileType (stat.st_mode, Native.FilePermissions.S_IFLNK);}
                }
 
                public bool IsSocket {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_IFSOCK);}
+                       get {AssertValid (); return IsFileType (stat.st_mode, Native.FilePermissions.S_IFSOCK);}
                }
 
                public bool IsSetUser {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_ISUID);}
+                       get {AssertValid (); return IsSet (stat.st_mode, Native.FilePermissions.S_ISUID);}
                }
 
                public bool IsSetGroup {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_ISGID);}
+                       get {AssertValid (); return IsSet (stat.st_mode, Native.FilePermissions.S_ISGID);}
                }
 
                public bool IsSticky {
-                       get {AssertValid (); return IsType (stat.st_mode, Native.FilePermissions.S_ISVTX);}
+                       get {AssertValid (); return IsSet (stat.st_mode, Native.FilePermissions.S_ISVTX);}
                }
 
-               internal static bool IsType (Native.FilePermissions mode, Native.FilePermissions type)
+               internal static bool IsFileType (Native.FilePermissions mode, Native.FilePermissions type)
+               {
+                       return (mode & Native.FilePermissions.S_IFMT) == type;
+               }
+
+               internal static bool IsSet (Native.FilePermissions mode, Native.FilePermissions type)
                {
                        return (mode & type) == type;
                }
@@ -388,9 +392,9 @@ namespace Mono.Unix {
                        int r = Native.Syscall.lstat (path, out stat);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
 
-                       if (IsType (stat.st_mode, Native.FilePermissions.S_IFDIR))
+                       if (IsFileType (stat.st_mode, Native.FilePermissions.S_IFDIR))
                                return new UnixDirectoryInfo (path, stat);
-                       else if (IsType (stat.st_mode, Native.FilePermissions.S_IFLNK))
+                       else if (IsFileType (stat.st_mode, Native.FilePermissions.S_IFLNK))
                                return new UnixSymbolicLinkInfo (path, stat);
                        return new UnixFileInfo (path, stat);
                }
index 0497636b2469a37b9435b8d8aad919334391e95a..c032c02e79c103fecad792fb2e80f437f2272917 100644 (file)
@@ -82,7 +82,7 @@ namespace Mono.Unix {
 
                public string[] GetMemberNames ()
                {
-                       return group.gr_mem;
+                       return (string[]) group.gr_mem.Clone ();
                }
 
                public override int GetHashCode ()