namespace Mono.Unix {
- public class UnixDirectoryInfo : UnixFileSystemInfo
+ public sealed class UnixDirectoryInfo : UnixFileSystemInfo
{
public UnixDirectoryInfo (string path)
: base (path)
{
}
+ 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);
}
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 ();
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 ();
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);
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);
+ }
}
}