From afca464d3dbdcda1b10066cfdf777b4fa31838db Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Sun, 26 Jan 2025 09:07:33 -0800 Subject: [PATCH] Fix wrong error when disk is full #531 --- NAPS2.Lib/Pdf/SavePdfOperation.cs | 2 +- NAPS2.Sdk/Util/FileSystemHelper.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/NAPS2.Lib/Pdf/SavePdfOperation.cs b/NAPS2.Lib/Pdf/SavePdfOperation.cs index db00bd7612..51a34cd148 100644 --- a/NAPS2.Lib/Pdf/SavePdfOperation.cs +++ b/NAPS2.Lib/Pdf/SavePdfOperation.cs @@ -114,7 +114,7 @@ public bool Start(string fileName, Placeholders placeholders, ICollection /// Creates the parent directory for the provided path if needed. /// @@ -15,6 +18,10 @@ public static void EnsureParentDirExists(string filePath) } } + // TODO: Can we detect this on Linux/Mac? + public static bool IsDiskFullException(IOException exception) => + exception.HResult is HR_ERROR_DISK_FULL or HR_ERROR_HANDLE_DISK_FULL; + public static bool IsFileInUse(string filePath, out Exception? exception) { if (File.Exists(filePath)) @@ -34,7 +41,7 @@ public static bool IsFileInUse(string filePath, out Exception? exception) exception = null; return false; } - + // https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive) {