Pash-Project/Pash — pull request #93 by b333z (2013-04-21 12:33:51+00:00)
Title: Work around Mono GetDrives() bug

The results of System.IO.DriveInfo.GetDrives() is incorrect on my
system, returning a single entry with a blank name.

This commit works around the issue by catching this condition when
running on *nix platforms, and returning a single drive called root.

*nix like operating systems are less reliant on the concept of a drive
anyway, so this allows Pash to continue operation and still represent
the cwd.

I've been watching problem through the Mono versions but has remained, currently I'm on Mono 3.0.7.

Not sure what is different about my system that causes this issue, but my guess is it has something to do with the number or type of the filesystem's (> 100 zfs filesystem's, 122 entries in all listed by mount command)

I will do some debugging on Mono and try to submit a bug/patch but in the meantime this seems like a good way to deal with the issue in case it also effects others.

I'm all good to rework this if anyone has any suggestions to make it cleaner or deal with in a different way.

Here is a test program that shows the bug:
```
$ cat DriveInfoTest.cs
using System;
using System.IO;

class Test
{
public static void Main()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();

foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive: {0}", d.Name);
Console.WriteLine("Drive.RootDirectory: {0}", d.RootDirectory);
Console.WriteLine(" File type: {0}", d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
Console.WriteLine(
" Available space to current user:{0, 15} bytes",
d.AvailableFreeSpace);

Console.WriteLine(
" Total available space: {0, 15} bytes",
d.TotalFreeSpace);

Console.WriteLine(
" Total size of drive: {0, 15} bytes ",
d.TotalSize);
}
}
}
}
$ mono ./DriveInfoTest.exe
Drive:

Unhandled Exception:
System.ArgumentException: An empty file name is not valid.
at System.IO.FileSystemInfo.CheckPath (System.String path) [0x00000] in :0
at System.IO.DirectoryInfo..ctor (System.String path, Boolean simpleOriginalPath) [0x00000] in :0
at System.IO.DirectoryInfo..ctor (System.String path) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:.ctor (string)
at System.IO.DriveInfo.get_RootDirectory () [0x00000] in :0
at Test.Main () [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: An empty file name is not valid.
at System.IO.FileSystemInfo.CheckPath (System.String path) [0x00000] in :0
at System.IO.DirectoryInfo..ctor (System.String path, Boolean simpleOriginalPath) [0x00000] in :0
at System.IO.DirectoryInfo..ctor (System.String path) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:.ctor (string)
at System.IO.DriveInfo.get_RootDirectory () [0x00000] in :0
at Test.Main () [0x00000] in :0
```