* UnixFileSystemInfo.cs: Create() should return a UnixFileInfo if the file
authorJonathan Pryor <jpryor@novell.com>
Thu, 23 Feb 2006 16:08:06 +0000 (16:08 -0000)
committerJonathan Pryor <jpryor@novell.com>
Thu, 23 Feb 2006 16:08:06 +0000 (16:08 -0000)
    doesn't exist.  This allows callers to use UnixFileInfo.Exists to see if
    the file exists, and behaves more rationally e.g. if the directory
    contents changes while calling UnixDirectoryInfo.GetFileSystemEntries(),
    we'll get a UnixFileInfo entry that doesn't exist instead of an exception
    terminating the entire array creation.
  * UnixSymbolicLinkInfo.cs: [Obsolete] the Contents property -- this property
    *always* creates a new object if HasContents=true, and since a
    UnixFileSystemInfo instance is (104+2*(sizeof(void*))+1) bytes (~113 bytes
    on 32-bit platforms), we don't want to create these frequently.  Add a
    GetContents() method as the replacement, to make it (slightly) more
    explicit that information won't be cached (and thus should be cached by
    the caller, if appropriate).  GetContents() throws an exception if
    HasContents=false instead of returning null; this change brings the
    implementation in line with the documentation.

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

mcs/class/Mono.Posix/Mono.Unix/ChangeLog
mcs/class/Mono.Posix/Mono.Unix/UnixFileSystemInfo.cs
mcs/class/Mono.Posix/Mono.Unix/UnixSymbolicLinkInfo.cs

index 5dddfe9f69aeb50a07e1c24a2f069f0b62ab2394..47cf313d9d0595c4509ebcfef8ab26eec29973a5 100644 (file)
@@ -1,3 +1,21 @@
+2006-02-23  Jonathan Pryor  <jonpryor@vt.edu>
+
+       * UnixFileSystemInfo.cs: Create() should return a UnixFileInfo if the file
+         doesn't exist.  This allows callers to use UnixFileInfo.Exists to see if
+         the file exists, and behaves more rationally e.g. if the directory
+         contents changes while calling UnixDirectoryInfo.GetFileSystemEntries(),
+         we'll get a UnixFileInfo entry that doesn't exist instead of an exception
+         terminating the entire array creation.
+       * UnixSymbolicLinkInfo.cs: [Obsolete] the Contents property -- this property
+         *always* creates a new object if HasContents=true, and since a
+         UnixFileSystemInfo instance is (104+2*(sizeof(void*))+1) bytes (~113 bytes
+         on 32-bit platforms), we don't want to create these frequently.  Add a
+         GetContents() method as the replacement, to make it (slightly) more
+         explicit that information won't be cached (and thus should be cached by
+         the caller, if appropriate).  GetContents() throws an exception if
+         HasContents=false instead of returning null; this change brings the
+         implementation in line with the documentation.
+
 2006-02-18  Alp Toker  <alp@atoker.com>
 
        * UnixEndPoint.cs: Avoid truncation of last two bytes of SocketAddress
index 34a0139c38b50afa8544ac83052ab84733e6adfe..f9cd3563e7ea739784fbc260becf3ea05442b837 100644 (file)
@@ -390,6 +390,9 @@ namespace Mono.Unix {
                {
                        Native.Stat stat;
                        int r = Native.Syscall.lstat (path, out stat);
+                       if (r == -1 && Native.Stdlib.GetLastError() == Native.Errno.ENOENT) {
+                               return new UnixFileInfo (path);
+                       }
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
 
                        if (IsFileType (stat.st_mode, Native.FilePermissions.S_IFDIR))
index 57b71ca1fed337e94f35e282ab438fbdd92ceae6..b469af311e37bf6204e05d5466c7e52c61992e9d 100644 (file)
@@ -49,13 +49,9 @@ namespace Mono.Unix {
                        get {return UnixPath.GetFileName (FullPath);}
                }
 
+               [Obsolete ("Use GetContents()")]
                public UnixFileSystemInfo Contents {
-                       get {
-                               string path = TryReadLink ();
-                               if (path != null)
-                                       return UnixFileSystemInfo.Create (ContentsPath);
-                               return null;
-                       }
+                       get {return GetContents ();}
                }
 
                public string ContentsPath {
@@ -70,6 +66,14 @@ namespace Mono.Unix {
                        }
                }
 
+               public UnixFileSystemInfo GetContents ()
+               {
+                       string path = ReadLink ();
+                       return UnixFileSystemInfo.Create (
+                                               UnixPath.Combine (UnixPath.GetDirectoryName (FullPath), 
+                                                       ContentsPath));
+               }
+
                public void CreateSymbolicLinkTo (string path)
                {
                        int r = Native.Syscall.symlink (path, FullName);