* UnixDirectoryInfo.cs, UnixDriveInfo.cs, UnixEnvironment.cs,
[mono.git] / mcs / class / Mono.Posix / Mono.Unix / UnixDirectoryInfo.cs
index ae97037cdcb9b608e5f83652a2ceb3b76cddb4f9..2def70312257ddffe3d535250c2b4e407c593bd1 100644 (file)
@@ -35,7 +35,7 @@ using Mono.Unix;
 
 namespace Mono.Unix {
 
-       public class UnixDirectoryInfo : UnixFileSystemInfo
+       public sealed class UnixDirectoryInfo : UnixFileSystemInfo
        {
                public UnixDirectoryInfo (string path)
                        : base (path)
@@ -47,16 +47,54 @@ namespace Mono.Unix {
                {
                }
 
+               public override string Name {
+                       get {
+                               string r = UnixPath.GetFileName (FullPath);
+                               if (r == null || r.Length == 0)
+                                       return FullPath;
+                               return r;
+                       }
+               }
+
+               public UnixDirectoryInfo Parent {
+                       get {
+                               string dirname = UnixPath.GetDirectoryName (FullPath);
+                               if (dirname == null)
+                                       return null;
+                               return new UnixDirectoryInfo (dirname);
+                       }
+               }
+
+               public UnixDirectoryInfo Root {
+                       get {
+                               string root = UnixPath.GetPathRoot (FullPath);
+                               if (root == null)
+                                       return null;
+                               return new UnixDirectoryInfo (root);
+                       }
+               }
+
+               [CLSCompliant (false)]
+               [Obsolete ("Use Create(Mono.Unix.Native.FilePermissions)")]
                public void Create (FilePermissions mode)
                {
-                       int r = Syscall.mkdir (Path, mode);
+                       Mono.Unix.Native.FilePermissions _mode = 
+                               (Mono.Unix.Native.FilePermissions) mode;
+                       Create (_mode);
+               }
+
+               [CLSCompliant (false)]
+               public void Create (Mono.Unix.Native.FilePermissions mode)
+               {
+                       int r = Mono.Unix.Native.Syscall.mkdir (FullPath, mode);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                        base.Refresh ();
                }
 
                public void Create ()
                {
-                       FilePermissions mode = FilePermissions.ACCESSPERMS;
+                       Mono.Unix.Native.FilePermissions mode = 
+                               Mono.Unix.Native.FilePermissions.ACCESSPERMS;
                        Create (mode);
                }
 
@@ -76,14 +114,15 @@ namespace Mono.Unix {
                                                e.Delete ();
                                }
                        }
-                       int r = Syscall.rmdir (Path);
+                       int r = Syscall.rmdir (FullPath);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                        base.Refresh ();
                }
 
+               [Obsolete ("The return type will change to Mono.Unix.Native.Dirent[] in the next release")]
                public Dirent[] GetEntries ()
                {
-                       IntPtr dirp = Syscall.opendir (Path);
+                       IntPtr dirp = Syscall.opendir (FullPath);
                        if (dirp == IntPtr.Zero)
                                UnixMarshal.ThrowExceptionForLastError ();
 
@@ -121,9 +160,10 @@ namespace Mono.Unix {
                        return (Dirent[]) entries.ToArray (typeof(Dirent));
                }
 
+               [Obsolete ("The return type will change to Mono.Unix.Native.Dirent[] in the next release")]
                public Dirent[] GetEntries (Regex regex)
                {
-                       IntPtr dirp = Syscall.opendir (Path);
+                       IntPtr dirp = Syscall.opendir (FullPath);
                        if (dirp == IntPtr.Zero)
                                UnixMarshal.ThrowExceptionForLastError ();
 
@@ -157,6 +197,7 @@ namespace Mono.Unix {
                        return (Dirent[]) entries.ToArray (typeof(Dirent));
                }
 
+               [Obsolete ("The return type will change to Mono.Unix.Native.Dirent[] in the next release")]
                public Dirent[] GetEntries (string regex)
                {
                        Regex re = new Regex (regex);
@@ -188,6 +229,25 @@ namespace Mono.Unix {
                        Regex re = new Regex (regex);
                        return GetFileSystemEntries (re);
                }
+
+               public static string GetCurrentDirectory ()
+               {
+                       StringBuilder buf = new StringBuilder (16);
+                       IntPtr r = IntPtr.Zero;
+                       do {
+                               buf.Capacity *= 2;
+                               r = Syscall.getcwd (buf, (ulong) buf.Capacity);
+                       } while (r == IntPtr.Zero && Syscall.GetLastError() == Error.ERANGE);
+                       if (r == IntPtr.Zero)
+                               UnixMarshal.ThrowExceptionForLastError ();
+                       return buf.ToString ();
+               }
+
+               public static void SetCurrentDirectory (string path)
+               {
+                       int r = Syscall.chdir (path);
+                       UnixMarshal.ThrowExceptionForLastErrorIf (r);
+               }
        }
 }