forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: FileStream.Dispose silently fails on Dispose when disk has run o…
…ut of space (dotnet#38742) * Save last error info in SafeFileHandle.ReleaseHandle and read it in FileStream.Dispose * Add manual test * Remove Debug.Fail from SafeFileHandle, automate the drive filling step in the manual test, add suggested comments, make threadstatic field static. * Address suggestions * Update src/libraries/System.IO.FileSystem/tests/ManualTests/ManualTests.cs Co-authored-by: Jan Kotas <[email protected]> Co-authored-by: carlossanlop <[email protected]> Co-authored-by: Jan Kotas <[email protected]>
- Loading branch information
1 parent
65e51b7
commit 09048de
Showing
5 changed files
with
114 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/libraries/System.IO.FileSystem/tests/ManualTests/ManualTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.IO; | ||
using Microsoft.DotNet.XUnitExtensions; | ||
using Xunit; | ||
|
||
namespace System.IO.ManualTests | ||
{ | ||
public class FileSystemManualTests | ||
{ | ||
public static bool ManualTestsEnabled => !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("MANUAL_TESTS")); | ||
|
||
[ConditionalFact(nameof(ManualTestsEnabled))] | ||
[PlatformSpecific(TestPlatforms.AnyUnix)] | ||
public static void Throw_FileStreamDispose_WhenRemoteMountRunsOutOfSpace() | ||
{ | ||
/* | ||
Example of mounting a remote folder using sshfs and two Linux machines: | ||
In remote machine: | ||
- Install openssh-server. | ||
- Create an ext4 partition of 1 MB size. | ||
In local machine: | ||
- Install sshfs and openssh-client. | ||
- Create a local folder inside the current user's home, named "mountedremote": | ||
$ mkdir ~/mountedremote | ||
- Mount the remote folder into "mountedremote": | ||
$ sudo sshfs -o allow_other,default_permissions [email protected]:/home/remoteuser/share /home/localuser/mountedremote | ||
- Set the environment variable MANUAL_TESTS=1 | ||
- Run this manual test. | ||
- Expect the exception. | ||
- Unmount the folder: | ||
$ fusermount -u ~/mountedremote | ||
*/ | ||
|
||
string mountedPath = $"{Environment.GetEnvironmentVariable("HOME")}/mountedremote"; | ||
string largefile = $"{mountedPath}/largefile.txt"; | ||
string origin = $"{mountedPath}/copyme.txt"; | ||
string destination = $"{mountedPath}/destination.txt"; | ||
|
||
// Ensure the remote folder exists | ||
Assert.True(Directory.Exists(mountedPath)); | ||
|
||
// Delete copied file if exists | ||
if (File.Exists(destination)) | ||
{ | ||
File.Delete(destination); | ||
} | ||
|
||
// Create huge file if not exists | ||
if (!File.Exists(largefile)) | ||
{ | ||
File.WriteAllBytes(largefile, new byte[925696]); | ||
} | ||
|
||
// Create original file if not exists | ||
if (!File.Exists(origin)) | ||
{ | ||
File.WriteAllBytes(origin, new byte[8192]); | ||
} | ||
|
||
Assert.True(File.Exists(largefile)); | ||
Assert.True(File.Exists(origin)); | ||
|
||
using FileStream originStream = new FileStream(origin, FileMode.Open, FileAccess.Read); | ||
Stream destinationStream = new FileStream(destination, FileMode.Create, FileAccess.Write); | ||
originStream.CopyTo(destinationStream, 1); | ||
|
||
Assert.Throws<IOException>(() => | ||
{ | ||
destinationStream.Dispose(); | ||
}); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...libraries/System.IO.FileSystem/tests/ManualTests/System.IO.FileSystem.Manual.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="ManualTests.cs" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters