File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -9,16 +9,23 @@ namespace Bloxstrap.Utility
99{
1010 internal static class Filesystem
1111 {
12- internal static long GetFreeDiskSpace ( string path )
12+ internal static long GetFreeDiskSpace ( string p )
1313 {
14- foreach ( var drive in DriveInfo . GetDrives ( ) )
15- {
16- // https://github.com/bloxstraplabs/bloxstrap/issues/1648#issuecomment-2192571030
17- if ( path . ToUpperInvariant ( ) . StartsWith ( drive . Name ) )
14+ try {
15+ if ( ! Path . IsPathRooted ( p ) || ! Path . IsPathFullyQualified ( p ) ) {
16+ return - 1 ;
17+ }
18+ var root = Path . GetPathRoot ( p ) ;
19+ if ( root != null ) {
20+ var drive = new DriveInfo ( root ) ;
1821 return drive . AvailableFreeSpace ;
22+ } else {
23+ throw new ArgumentException ( "Invalid path" , nameof ( p ) ) ;
24+ }
25+ } catch ( ArgumentException e ) {
26+ App . Logger . WriteLine ( "Filesystem::BadPath" , $ "The path: { e } does not contain valid drive info.") ;
27+ return - 1 ;
1928 }
20-
21- return - 1 ;
2229 }
2330
2431 internal static void AssertReadOnly ( string filePath )
You can’t perform that action at this time.
0 commit comments