@ -17,7 +17,6 @@ namespace NzbDrone.Common
DateTime GetLastFolderWrite ( string path ) ;
DateTime GetLastFolderWrite ( string path ) ;
DateTime GetLastFileWrite ( string path ) ;
DateTime GetLastFileWrite ( string path ) ;
void EnsureFolder ( string path ) ;
void EnsureFolder ( string path ) ;
bool FolderExists ( string path , bool caseSensitive ) ;
bool FolderExists ( string path ) ;
bool FolderExists ( string path ) ;
bool FileExists ( string path ) ;
bool FileExists ( string path ) ;
bool FileExists ( string path , bool caseSensitive ) ;
bool FileExists ( string path , bool caseSensitive ) ;
@ -32,7 +31,7 @@ namespace NzbDrone.Common
void MoveFile ( string source , string destination ) ;
void MoveFile ( string source , string destination ) ;
void DeleteFolder ( string path , bool recursive ) ;
void DeleteFolder ( string path , bool recursive ) ;
void InheritFolderPermissions ( string filename ) ;
void InheritFolderPermissions ( string filename ) ;
long GetAv ilableSpace( string path ) ;
long ? GetAv a ilableSpace( string path ) ;
string ReadAllText ( string filePath ) ;
string ReadAllText ( string filePath ) ;
void WriteAllText ( string filename , string contents ) ;
void WriteAllText ( string filename , string contents ) ;
void FileSetLastWriteTimeUtc ( string path , DateTime dateTime ) ;
void FileSetLastWriteTimeUtc ( string path , DateTime dateTime ) ;
@ -113,16 +112,6 @@ namespace NzbDrone.Common
return Directory . Exists ( path ) ;
return Directory . Exists ( path ) ;
}
}
public bool FolderExists ( string path , bool caseSensitive )
{
if ( caseSensitive )
{
return FolderExists ( path ) & & path = = path . GetActualCasing ( ) ;
}
return FolderExists ( path ) ;
}
public bool FileExists ( string path )
public bool FileExists ( string path )
{
{
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;
@ -289,26 +278,37 @@ namespace NzbDrone.Common
File . SetAccessControl ( filename , fs ) ;
File . SetAccessControl ( filename , fs ) ;
}
}
public long GetAv ilableSpace( string path )
public long ? GetAv a ilableSpace( string path )
{
{
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;
var root = GetPathRoot ( path ) ;
if ( ! FolderExists ( root ) )
throw new DirectoryNotFoundException ( root ) ;
if ( OsInfo . IsLinux )
if ( OsInfo . IsLinux )
{
{
var driveInfo = DriveInfo . GetDrives ( ) . SingleOrDefault ( c = > c . IsReady & & path . StartsWith ( c . Name , StringComparison . CurrentCultureIgnoreCase ) ) ;
var drive s = DriveInfo . GetDrives ( ) ;
if ( driveInfo = = null )
foreach ( var drive in drives )
{
{
throw new DirectoryNotFoundException ( path ) ;
try
{
if ( drive . IsReady & & path . StartsWith ( drive . Name , StringComparison . CurrentCultureIgnoreCase ) )
{
return drive . AvailableFreeSpace ;
}
}
catch ( InvalidOperationException e )
{
Logger . ErrorException ( "Couldn't get free space for " + path , e ) ;
}
}
return driveInfo . AvailableFreeSpace ;
}
}
var root = GetPathRoot ( path ) ;
return null ;
}
if ( ! FolderExists ( root ) )
throw new DirectoryNotFoundException ( root ) ;
return DriveFreeSpaceEx ( root ) ;
return DriveFreeSpaceEx ( root ) ;
}
}