Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 5a8285f

Browse files
committed
Address PR feedback
1 parent daf9745 commit 5a8285f

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/System.IO.FileSystem/src/System/IO/Win32FileStream.cs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,22 +1688,45 @@ private int GetLastWin32ErrorAndDisposeHandleIfInvalid(bool throwIfInvalidHandle
16881688
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
16891689
{
16901690
// Validate arguments as would the base implementation
1691-
if (destination == null) throw new ArgumentNullException(nameof(destination));
1692-
if (bufferSize <= 0) throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
1691+
if (destination == null)
1692+
{
1693+
throw new ArgumentNullException(nameof(destination));
1694+
}
1695+
if (bufferSize <= 0)
1696+
{
1697+
throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
1698+
}
16931699
bool parentCanRead = _parent.CanRead;
1694-
if (!parentCanRead && !_parent.CanWrite) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
1700+
if (!parentCanRead && !_parent.CanWrite)
1701+
{
1702+
throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
1703+
}
16951704
bool destinationCanWrite = destination.CanWrite;
1696-
if (!destination.CanRead && !destinationCanWrite) throw new ObjectDisposedException(nameof(destination), SR.ObjectDisposed_StreamClosed);
1697-
if (!parentCanRead) throw new NotSupportedException(SR.NotSupported_UnreadableStream);
1698-
if (!destinationCanWrite) throw new NotSupportedException(SR.NotSupported_UnwritableStream);
1699-
if (_handle.IsClosed) throw Error.GetFileNotOpen();
1705+
if (!destination.CanRead && !destinationCanWrite)
1706+
{
1707+
throw new ObjectDisposedException(nameof(destination), SR.ObjectDisposed_StreamClosed);
1708+
}
1709+
if (!parentCanRead)
1710+
{
1711+
throw new NotSupportedException(SR.NotSupported_UnreadableStream);
1712+
}
1713+
if (!destinationCanWrite)
1714+
{
1715+
throw new NotSupportedException(SR.NotSupported_UnwritableStream);
1716+
}
17001717

17011718
// Bail early for cancellation if cancellation has been requested
17021719
if (cancellationToken.IsCancellationRequested)
17031720
{
17041721
return Task.FromCanceled<int>(cancellationToken);
17051722
}
17061723

1724+
// Fail if the file was closed
1725+
if (_handle.IsClosed)
1726+
{
1727+
throw Error.GetFileNotOpen();
1728+
}
1729+
17071730
// Do the async copy, with differing implementations based on whether the FileStream was opened as async or sync
17081731
Debug.Assert((_readPos == 0 && _readLen == 0 && _writePos >= 0) || (_writePos == 0 && _readPos <= _readLen), "We're either reading or writing, but not both.");
17091732
return _isAsync ?
@@ -1745,7 +1768,10 @@ private async Task AsyncModeCopyToAsync(Stream destination, int bufferSize, Canc
17451768
bool canSeek = _parent.CanSeek;
17461769
if (canSeek)
17471770
{
1748-
if (_exposedHandle) VerifyOSHandlePosition();
1771+
if (_exposedHandle)
1772+
{
1773+
VerifyOSHandlePosition();
1774+
}
17491775
readAwaitable._position = _pos;
17501776
}
17511777

0 commit comments

Comments
 (0)