-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/6.0-rc2] File preallocationSize: align Windows and Unix beha…
…vior. (#59532) * Align preallocationSize behavior (#58726) Co-authored-by: Stephen Toub <[email protected]> * File preallocationSize: align Windows and Unix behavior. (#59338) * File preallocationSize: align Windows and Unix behavior. This aligns Windows and Unix behavior of preallocationSize for the intended use-case of specifing the size of a file that will be written. For this use-case, the expected FileAccess is Write, and the file should be a new one (FileMode.Create*) or a truncated file (FileMode.Truncate). Specifing a preallocationSize for other modes, or non-writable files throws ArgumentException. The opened file will have a length of zero, and is ready to be written to by the user. If the requested size cannot be allocated, an IOException is thrown. When the OS/filesystem does not support pre-allocating, preallocationSize is ignored. * fix pal_io preprocessor checks * pal_io more fixes * ctor_options_as.Windows.cs: fix compilation * Update tests * tests: use preallocationSize from all public APIs * pal_io: add back FreeBSD, fix OSX * tests: check allocated is zero when preallocation is not supported. * Only throw for not enough space errors * Fix compilation * Add some more tests * Fix ExtendedPathsAreSupported test * Apply suggestions from code review Co-authored-by: David Cantú <[email protected]> * Update System.Private.CoreLib Strings.resx * PR feedback * Remove GetPathToNonExistingFile * Fix compilation * Skip checking allocated size on mobile platforms. Co-authored-by: David Cantú <[email protected]> * Fix unused fileDescriptor * void fd when unused * Address feedback Co-authored-by: Adam Sitnik <[email protected]> Co-authored-by: Stephen Toub <[email protected]> Co-authored-by: Tom Deseyn <[email protected]>
- Loading branch information
1 parent
dc8ab40
commit 157d591
Showing
26 changed files
with
389 additions
and
412 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
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
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
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
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
17 changes: 17 additions & 0 deletions
17
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options.Browser.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,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.IO.Tests | ||
{ | ||
public partial class FileStream_ctor_options | ||
{ | ||
private static long GetAllocatedSize(FileStream fileStream) | ||
{ | ||
return 0; | ||
} | ||
|
||
private static bool SupportsPreallocation => false; | ||
|
||
private static bool IsGetAllocatedSizeImplemented => false; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options.Unix.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,36 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace System.IO.Tests | ||
{ | ||
public partial class FileStream_ctor_options | ||
{ | ||
private static long GetAllocatedSize(FileStream fileStream) | ||
{ | ||
bool isOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); | ||
// Call 'stat' to get the number of blocks, and size of blocks. | ||
using var px = Process.Start(new ProcessStartInfo | ||
{ | ||
FileName = "stat", | ||
ArgumentList = { isOSX ? "-f" : "-c", | ||
isOSX ? "%b %k" : "%b %B", | ||
fileStream.Name }, | ||
RedirectStandardOutput = true | ||
}); | ||
string stdout = px.StandardOutput.ReadToEnd(); | ||
|
||
string[] parts = stdout.Split(' '); | ||
return long.Parse(parts[0]) * long.Parse(parts[1]); | ||
} | ||
|
||
private static bool SupportsPreallocation => | ||
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || | ||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX); | ||
|
||
// Mobile platforms don't support Process.Start. | ||
private static bool IsGetAllocatedSizeImplemented => !PlatformDetection.IsMobile; | ||
} | ||
} |
Oops, something went wrong.