Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Fix deletion tests on Windows 10 1903. #38186

Merged
merged 1 commit into from
Jun 4, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public void FileShareDeleteNew()
{
Assert.True(File.Exists(fileName));
File.Delete(fileName);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // file sharing restriction limitations on Unix
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.True(File.Exists(fileName));
// Prior to 1903 Windows would not delete the filename until the last file handle is closed.
Assert.Equal(PlatformDetection.IsWindows10Version1903OrGreater, !File.Exists(fileName));
}
}

Expand Down Expand Up @@ -56,9 +57,10 @@ public void FileShareDeleteExisting()
using (FileStream fs = CreateFileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Delete))
{
File.Delete(fileName);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // file sharing restriction limitations on Unix
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.True(File.Exists(fileName));
// Prior to 1903 Windows would not delete the filename until the last file handle is closed.
Assert.Equal(PlatformDetection.IsWindows10Version1903OrGreater, !File.Exists(fileName));
}
}

Expand Down Expand Up @@ -104,16 +106,25 @@ public void FileShareDeleteExistingMultipleClients()
{
File.Delete(fileName);
Assert.Equal(0, fs2.ReadByte());
Assert.True(File.Exists(fileName), $"'{fileName}' should still exist after calling delete with two handles open.");

// Prior to 1903 Windows would not delete the filename until the last file handle is closed.
Assert.Equal(PlatformDetection.IsWindows10Version1903OrGreater, !File.Exists(fileName));
}

Assert.Equal(0, fs1.ReadByte());
fs1.WriteByte(0xFF);

// Any attempt to reopen a file in pending-delete state will return Access-denied
Assert.Throws<UnauthorizedAccessException>(() => CreateFileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite));

Assert.True(File.Exists(fileName), $"'{fileName}' should still exist after calling delete with inner filestream closed.");
if (PlatformDetection.IsWindows10Version1903OrGreater)
{
// On 1903 the filename is immediately released after delete is called
Assert.Throws<FileNotFoundException>(() => CreateFileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite));
}
else
{
// Any attempt to reopen a file in pending-delete state will return Access-denied
Assert.Throws<UnauthorizedAccessException>(() => CreateFileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite));
Assert.True(File.Exists(fileName), $"'{fileName}' should still exist after calling delete with inner filestream closed.");
}
}

Assert.False(File.Exists(fileName));
Expand Down