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

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Sep 13, 2016
1 parent daf9745 commit 5a8285f
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions src/System.IO.FileSystem/src/System/IO/Win32FileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,22 +1688,45 @@ private int GetLastWin32ErrorAndDisposeHandleIfInvalid(bool throwIfInvalidHandle
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
{
// Validate arguments as would the base implementation
if (destination == null) throw new ArgumentNullException(nameof(destination));
if (bufferSize <= 0) throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
if (destination == null)
{
throw new ArgumentNullException(nameof(destination));
}
if (bufferSize <= 0)
{
throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
}
bool parentCanRead = _parent.CanRead;
if (!parentCanRead && !_parent.CanWrite) throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
if (!parentCanRead && !_parent.CanWrite)
{
throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
}
bool destinationCanWrite = destination.CanWrite;
if (!destination.CanRead && !destinationCanWrite) throw new ObjectDisposedException(nameof(destination), SR.ObjectDisposed_StreamClosed);
if (!parentCanRead) throw new NotSupportedException(SR.NotSupported_UnreadableStream);
if (!destinationCanWrite) throw new NotSupportedException(SR.NotSupported_UnwritableStream);
if (_handle.IsClosed) throw Error.GetFileNotOpen();
if (!destination.CanRead && !destinationCanWrite)
{
throw new ObjectDisposedException(nameof(destination), SR.ObjectDisposed_StreamClosed);
}
if (!parentCanRead)
{
throw new NotSupportedException(SR.NotSupported_UnreadableStream);
}
if (!destinationCanWrite)
{
throw new NotSupportedException(SR.NotSupported_UnwritableStream);
}

// Bail early for cancellation if cancellation has been requested
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<int>(cancellationToken);
}

// Fail if the file was closed
if (_handle.IsClosed)
{
throw Error.GetFileNotOpen();
}

// Do the async copy, with differing implementations based on whether the FileStream was opened as async or sync
Debug.Assert((_readPos == 0 && _readLen == 0 && _writePos >= 0) || (_writePos == 0 && _readPos <= _readLen), "We're either reading or writing, but not both.");
return _isAsync ?
Expand Down Expand Up @@ -1745,7 +1768,10 @@ private async Task AsyncModeCopyToAsync(Stream destination, int bufferSize, Canc
bool canSeek = _parent.CanSeek;
if (canSeek)
{
if (_exposedHandle) VerifyOSHandlePosition();
if (_exposedHandle)
{
VerifyOSHandlePosition();
}
readAwaitable._position = _pos;
}

Expand Down

0 comments on commit 5a8285f

Please sign in to comment.