@ -2,6 +2,7 @@
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Text.RegularExpressions ;
using NLog ;
using NzbDrone.Common.Disk ;
using NzbDrone.Common.Extensions ;
@ -17,6 +18,10 @@ namespace NzbDrone.Mono
{
private static string [ ] _fixedTypes = new [ ] { "ext3" , "ext2" , "ext4" , "vfat" , "fuseblk" , "xfs" , "jfs" , "msdos" , "ntfs" , "minix" , "hfs" , "hfsplus" , "qnx4" , "ufs" , "btrfs" } ;
private static string [ ] _networkDriveTypes = new [ ] { "cifs" , "nfs" , "nfs4" , "nfsd" , "sshfs" } ;
private static readonly Regex OctalRegex = new Regex ( @"\\\d{3}" , RegexOptions . Compiled ) ;
private const string PROC_MOUNTS_FILENAME = @"/proc/mounts" ;
private const string PROC_FILESYSTEMS_FILENAME = @"/proc/filesystems" ;
private static Dictionary < string , bool > _fileSystems ;
@ -31,16 +36,16 @@ namespace NzbDrone.Mono
{
try
{
if ( File . Exists ( @"/proc/mounts" ) )
if ( File . Exists ( PROC_MOUNTS_FILENAME ) )
{
var lines = File . ReadAllLines ( @"/proc/mounts" ) ;
var lines = File . ReadAllLines ( PROC_MOUNTS_FILENAME ) ;
return lines . Select ( ParseLine ) . OfType < IMount > ( ) . ToList ( ) ;
}
}
catch ( Exception ex )
{
_logger . Debug ( ex , "Failed to retrieve mounts from /proc/mounts" ) ;
_logger . Debug ( ex , "Failed to retrieve mounts from {0}", PROC_MOUNTS_FILENAME ) ;
}
return new List < IMount > ( ) ;
@ -53,9 +58,9 @@ namespace NzbDrone.Mono
var result = new Dictionary < string , bool > ( ) ;
try
{
if ( File . Exists ( @"/proc/filesystems" ) )
if ( File . Exists ( PROC_FILESYSTEMS_FILENAME ) )
{
var lines = File . ReadAllLines ( @"/proc/filesystems" ) ;
var lines = File . ReadAllLines ( PROC_FILESYSTEMS_FILENAME ) ;
foreach ( var line in lines )
{
@ -67,7 +72,7 @@ namespace NzbDrone.Mono
}
catch ( Exception ex )
{
_logger . Debug ( ex , "Failed to get filesystem types from /proc/filesystems, using default set." ) ;
_logger . Debug ( ex , "Failed to get filesystem types from {0}, using default set.", PROC_FILESYSTEMS_FILENAME ) ;
}
if ( result . Empty ( ) )
@ -86,11 +91,11 @@ namespace NzbDrone.Mono
private IMount ParseLine ( string line )
{
var split = line . Split ( ' ' ) ;
var split = line . Split ( ' ' ) .Select ( ExpandEscapes ) . ToArray ( ) ;
if ( split . Length ! = 6 )
{
_logger . Debug ( "Unable to parse r /proc/mount line: {0}" , line ) ;
_logger . Debug ( "Unable to parse {0} line: {1}", PROC_MOUNTS_FILENAME , line ) ;
}
var name = split [ 0 ] ;
@ -132,5 +137,10 @@ namespace NzbDrone.Mono
return result ;
}
private string ExpandEscapes ( string mount )
{
return OctalRegex . Replace ( mount , match = > match . Captures [ 0 ] . Value . FromOctalString ( ) ) ;
}
}
}