Skip to content

Commit

Permalink
Fix wrong error when disk is full
Browse files Browse the repository at this point in the history
cyanfish committed Jan 26, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 524ca25 commit afca464
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion NAPS2.Lib/Pdf/SavePdfOperation.cs
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ public bool Start(string fileName, Placeholders placeholders, ICollection<Proces
}
catch (IOException ex)
{
if (File.Exists(subFileName))
if (File.Exists(subFileName) && !FileSystemHelper.IsDiskFullException(ex))
{
InvokeError(MiscResources.FileInUse, ex);
}
9 changes: 8 additions & 1 deletion NAPS2.Sdk/Util/FileSystemHelper.cs
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@

internal static class FileSystemHelper
{
private const int HR_ERROR_HANDLE_DISK_FULL = unchecked((int) 0x80070027);
private const int HR_ERROR_DISK_FULL = unchecked((int) 0x80070070);

/// <summary>
/// Creates the parent directory for the provided path if needed.
/// </summary>
@@ -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)
{

0 comments on commit afca464

Please sign in to comment.