* FileStream SafeHandle ctor negative test fix
The tests were intermittently failing on desktop as the
constructor was closing the handle when it got finalized.
- Moved the negative tests into a new class (they were running redundantly with no changes)
- Stopped creating files where it wasn't needed
- Added specific test for checking handle state and disabled for desktop with active issue
* Was looking at the redundancy as functional at the end point, not that they were calling different constructors. Putting them back in the derived classes to avoid introducing constructor overload regressions.
Commit migrated from https://github.com/dotnet/corefx/commit/dbd01e7691932235e007e454a1b7d7934b582de9
* Fix Unix missing file state
In the original .NET implementation a missing file never
throws directly with FileInfo. Attributes get the error result
from Windows (-1) and times aren't initialized.
* Feedback
* Change FileSystemTest derivation
FileSystemTest should derive from RemoteFileSystemTest so
we can have one base class.
* Add RemoteExecutorBase to performance test project
* Address test feedback
* Fix File.GetAttributes on Unix
NetFX doesn't rely on FileInfo and throws when getting attributes
on missing files through File.
Commit migrated from https://github.com/dotnet/corefx/commit/801dde95a5eac06140d0ac633ac3f9bfdd25aca5
The FileShareOpen test has been failing sporadically with sharing violations. It turns out the problem has to do with FileShare.Inheritable being included in the list of FileShare values to test. If another test in the same process concurrently spawns a process while a FileShare.Inheritable file is open, that file's handle will be inherited into the child process, which will in turn keep the file in use for longer than the test expects. When it then tries to re-open the file, it may encounter a sharing violation if the subsequent open is incompatible with the previous one's FileShare.
Commit migrated from https://github.com/dotnet/corefx/commit/041672ff3642753807a4502a4c407cb82bfa1009
* Marking code as unchecked (pt 9)
Additional unchecked for new test code and missed cases in BitConverter
* Marking code as unchecked (pt 9a)
Added unchecked to two casts in ManagedWebSocket
* CI test failure fixes
Overflow exceptions in:
- Windows NT Debug dotnet/corefx#3458
- OS X Debug dotnet/corefx#3357
* CI test failure fixes
Overflow exceptions in:
- Windows 7 Debug Outerloop (build 8)
- OS X Debug Outerloop (build 45)
* CI test failure fixes
Fixed overflow exception from OS X Debug Outerloop (build 46)
Commit migrated from https://github.com/dotnet/corefx/commit/7f6ac8bf97a84666ed3e7ef6b77c1a9470ae78c8
Adds negative tests for Begin/End, removes unnecessary block for `\\.\`
paths.
(The block for `\\.\` paths fulfills a need that predates our supported
Windows OSes. You cannot inadvertently mess up "raw" drives. In addition
we currently allow `\\?\` which is another form of device path access.)
Commit migrated from https://github.com/dotnet/corefx/commit/5376c25bea9523265696ed5806f3dc8b51bbbf25
Adds:
- File.WriteAllLines(string, string[])
- File.WriteAllLines(string, string[], Encoding)
- File.Replace(string, string, string)
- File.Replace(string, string, string, bool)
- File.Encrypt(string)
- File.Decrypt(string)
- FileInfo.Encrypt()
- FileInfo.Decrypt()
- FileStream.Handle
- FileStream.Lock(long, long)
- FileStream.Unlock(long, long)
Currently throws PlatformNotSupportedException from:
- Encrypt/Decrypt on all platforms. These can be implemented on Win32, but the APIs needed are not currently exposed as allowed in buildtools.
- Lock/Unlock on Unix and WinRT. These can be implemented on Unix; I just didn't in this commit.
Commit migrated from https://github.com/dotnet/corefx/commit/2fbc772ea8bd83a37b9f26c1a7c928a6be2d2c0b
The new FileStreamBase.Begin/End overloads do argument and state validation similar to that of desktop. There is a subtle but critical difference, however: in this validation, desktop checks to see whether the stream is closed via ```_handle.IsClosed```, whereas FileStreamBase does it via ```SafeFileHandle.IsClosed```. ```SafeFileHandle``` is an abstract property that returns the handle... but it also flushes. The base Stream's Begin/End implementation has synchronization to ensure that only one async operation is in flight at a time, but this call to ```SafeFileHandle.IsClosed``` comes before that synchronization kicks in (it's in the base), and as such we end up potentially having a Flush invocations concurrently with Write invocations (Write is called asynchronously from the base BeginWrite), which is very unsafe.
This commit fixes it by adding an IsClosed property that goes directly to the underlying handle, bypassing the publicly exposed SafeFileHandle (that flushes so that direct access to the file via the handle is consistent with operations already performed on the FileStream).
(I also fixed a small issue in the ManyConcurrentWriteAsyncs that highlighted the issue. Order of async read/write operations is only guaranteed on FileStream when in async mode; in non-async mode, it's theoretically possible (though unlikely) for operations to complete out-of-order, but the test is validating that the operations completed in order. While I've never seen this fail, I'm proactively fixing it.)
Commit migrated from https://github.com/dotnet/corefx/commit/5afb9f69400cbb61971a7eeb4fcfc49fbbc1080b
FileStream can be used with any arbitrary file descriptor on Unix. FileStream.Flush may use FSync to try to synchronize the file's state with the storage device, but that only makes sense and works for certain kinds of file descriptors. For other file descriptors, currently we're throwing an exception if the operation fails, when really we should just ignore the failure, as there's no work to be done.
Commit migrated from https://github.com/dotnet/corefx/commit/1994ac4a43105cda48c2fbcdf967d6ae48330e0e
Changes:
- An outerloop test verifying that we would throw when trying to use File.ReadAllBytes to read a > 2GB file was first writing out 2GB worth of data to disk. We can instead just create a FileStream and explicitly change its length. On my machine, this changes the execution time of that test from ~25s to just a few milliseconds.
- Two "mini stress" tests are enabled in outerloop and are explicitly coded to run for 30 seconds doing lots of reading and writing. I've changed these to be 10 seconds.
Commit migrated from https://github.com/dotnet/corefx/commit/e4c1fed1843c2dc80b9b345d6fac0251e865a227
FileStream's ctors allow the creator of the stream to specify whether asynchronous I/O should be used. The default in the full framework is false. When FileStream was ported to corefx, the default was changed to true.
Such a default of true can be beneficial, as it means that ReadAsync/WriteAsync calls on streams created without overriding that default will naturally use overlapped I/O on Windows, which can lead to better scalability and performance. However, there are other ramifications, in particular for existing code and code written to be portable across .NET implementations. For example:
- Using Read/Write on a stream created with useAsync=true ends up blocking as calls around Read/WriteAsync, making them more expensive than they'd otherwise be. So existing code that uses a FileStream for simple read/writes may actually get slower.
- The SafeFileHandle exposed from the FileStream naturally is associated with that particular async setting, such that attempting to use it to construct a FileStream with a conflicting setting will fail with an exception.
- FileStreams constructed with useAsync=true have special behaviors around how the position of the stream is updated after an async operation is initiated, which means code written expecting one default may fail when run with a different default.
- Etc.
While there are benefits to changing the default, the cons outweigh the pros. A developer can always opt-in to useAsync=true, but it's better to keep the default consistent across all implementations, especially for code written to be portable across those implementations. This commit changes it back to be false.
Commit migrated from https://github.com/dotnet/corefx/commit/08991e80aa6ce5ab7e43265b30824a91f6112db4
flock on OSX can fail with ENOTSUP if "the referenced descriptor is not of the correct type", e.g. if it's a FIFO. Since we don't want to entirely prevent usage of FileStream with such file types on OSX, and since locking is already advisory only, this change just ignores rather than throws when flock fails with ENOTSUP.
Commit migrated from https://github.com/dotnet/corefx/commit/38177bc1de3a73ef5e8b5f449478ea588406a4b4
The default CopyToAsync on Stream uses an 80K temporary buffer, making it a good candidate for buffer pooling. But Stream is in mscorlib and can't rely on System.Buffers. So this commit introduces an implementation that streams in mscorlib can use, just by overriding CopyToAsync and delegating. It then uses that in DeflateStream, GZipStream, FileStream, PipeStream, and UnmanagedMemoryStream.
Commit migrated from https://github.com/dotnet/corefx/commit/34ce38bc1517e8b7693223a9e41479dd24abc59a
Currently, the tests System.IO.Tests.FileStream_SafeFileHandle.
ThrowWhenHandlePositionIsChanged and System.Net.NetworkInformation.
Tests.UnixPingUtilityTests.PacketSizeIsRespected hang when running on a
Unix machine with 1 thread. Declaring the tests async fixes this issue.
Commit migrated from https://github.com/dotnet/corefx/commit/6d15aa69e332866e6282994edfd2de5ca0192899