Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Pri.LongPath/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,23 @@ public static FileStream Create(string path, int bufferSize, FileOptions options
/// </exception>
public static void Delete(string path)
{
if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
{
SysFile.Delete(path);
return;
}
const int fileNotFoundWindowsErrorCode = 2;

string normalizedPath = Path.NormalizeLongPath(path);
if (!NativeMethods.DeleteFile(normalizedPath))
if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
{
throw Common.GetExceptionFromLastWin32Error();
SysFile.Delete(path);
return;
}

string normalizedPath = Path.NormalizeLongPath(path);

if (NativeMethods.DeleteFile(normalizedPath))
return;

if (fileNotFoundWindowsErrorCode == Marshal.GetLastWin32Error())
return;

throw Common.GetExceptionFromLastWin32Error();
}

public static void Decrypt(string path)
Expand Down
6 changes: 6 additions & 0 deletions Tests/FileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,12 @@ public void TestGetLastWriteTimeOnMissingFileHasNoException()
var dt = File.GetLastWriteTime("gibberish");
}

[Test]
public void TestDeleteOnMissingFileDoesNotThrow()
{
File.Delete("missing.file");
}

[TearDown]
public void TearDown()
{
Expand Down