* UnixFileSystemInfo.cs: rename Create() to GetFileSystemEntry(), and make
[mono.git] / mcs / class / Mono.Posix / Mono.Unix / UnixSymbolicLinkInfo.cs
index ca2fcd2501141fa4aed447666037b877143a5478..868dade2d513fc6349c22e89ca3c29d8b9239e82 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 UnixSymbolicLinkInfo (string path, Stat stat)
+               internal UnixSymbolicLinkInfo (string path, Native.Stat stat)
                        : base (path, stat)
                {
                }
@@ -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,42 +66,42 @@ namespace Mono.Unix {
                        }
                }
 
+               public UnixFileSystemInfo GetContents ()
+               {
+                       string path = ReadLink ();
+                       return UnixFileSystemInfo.GetFileSystemEntry (
+                                               UnixPath.Combine (UnixPath.GetDirectoryName (FullPath), 
+                                                       ContentsPath));
+               }
+
                public void CreateSymbolicLinkTo (string path)
                {
-                       int r = Syscall.symlink (path, OriginalPath);
+                       int r = Native.Syscall.symlink (path, FullName);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                }
 
                public void CreateSymbolicLinkTo (UnixFileSystemInfo path)
                {
-                       int r = Syscall.symlink (path.FullName, OriginalPath);
+                       int r = Native.Syscall.symlink (path.FullName, OriginalPath);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                }
 
                public override void Delete ()
                {
-                       int r = Syscall.unlink (FullPath);
+                       int r = Native.Syscall.unlink (FullPath);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                        base.Refresh ();
                }
 
-               [CLSCompliant (false)]
-               [Obsolete ("Use SetOwner (long, long)")]
-               public override void SetOwner (uint owner, uint group)
-               {
-                       int r = Syscall.lchown (FullPath, owner, group);
-                       UnixMarshal.ThrowExceptionForLastErrorIf (r);
-               }
-
                public override void SetOwner (long owner, long group)
                {
-                       int r = Syscall.lchown (FullPath, Convert.ToUInt32 (owner), Convert.ToUInt32 (group));
+                       int r = Native.Syscall.lchown (FullPath, Convert.ToUInt32 (owner), Convert.ToUInt32 (group));
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                }
 
-               protected override int GetFileStatus (string path, out Stat stat)
+               protected override bool GetFileStatus (string path, out Native.Stat stat)
                {
-                       return Syscall.lstat (path, out stat);
+                       return Native.Syscall.lstat (path, out stat) == 0;
                }
 
                private string ReadLink ()
@@ -118,7 +114,11 @@ namespace Mono.Unix {
 
                private string TryReadLink ()
                {
-                       return UnixPath.ReadSymbolicLink (FullPath);
+                       StringBuilder sb = new StringBuilder ((int) base.Length+1);
+                       int r = Native.Syscall.readlink (FullPath, sb);
+                       if (r == -1)
+                               return null;
+                       return sb.ToString (0, r);
                }
        }
 }