Skip to content

Commit dc51df9

Browse files
committed
CheckDiskSpace update to handle RAM drives
1 parent 047fc92 commit dc51df9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

ConfigParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public static List<string> GetList(this IConfiguration config, params string[] s
9696

9797
public static List<string> GetList(this IConfigurationSection config)
9898
{
99+
//TODO: detect also missing key and use a default value in such case
100+
99101
if (config.Value != null)
100102
return new List<string>() { config.Value };
101103
else

Program.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,19 +979,24 @@ public static async Task SaveFileModifications(string fullName, byte[] fileData,
979979
}
980980
} //public static async Task SaveFileModifications(string fullName, byte[] fileData, byte[] originalData, Context context)
981981

982-
public static long CheckDiskSpace(string path)
982+
public static long? CheckDiskSpace(string path)
983983
{
984-
long freeBytes;
984+
long? freeBytes = null;
985985

986-
if (!ConfigParser.IsWindows)
986+
try //NB! on some drives (for example, RAM drives, GetDiskFreeSpaceEx does not work
987987
{
988988
//NB! DriveInfo works on paths well in Linux //TODO: what about Mac?
989989
var drive = new DriveInfo(path);
990990
freeBytes = drive.AvailableFreeSpace;
991991
}
992-
else
992+
catch (ArgumentException)
993993
{
994-
WindowsDllImport.GetDiskFreeSpaceEx(path, out freeBytes, out var _, out var __);
994+
if (ConfigParser.IsWindows)
995+
{
996+
long freeBytesOut;
997+
if (WindowsDllImport.GetDiskFreeSpaceEx(path, out freeBytesOut, out var _, out var __))
998+
freeBytes = freeBytesOut;
999+
}
9951000
}
9961001

9971002
return freeBytes;

0 commit comments

Comments
 (0)