diff --git a/src/Tmds.Ssh/SftpClient.Writer.cs b/src/Tmds.Ssh/SftpClient.Writer.cs index 6a71feb..a9c3b56 100644 --- a/src/Tmds.Ssh/SftpClient.Writer.cs +++ b/src/Tmds.Ssh/SftpClient.Writer.cs @@ -232,7 +232,7 @@ private async ValueTask ExecuteAsync( PendingOperation? pendingOperation, CancellationToken cancellationToken) { - await ExecuteAsync(packet, id, pendingOperation, cancellationToken); + await ExecuteAsync(packet, id, pendingOperation, cancellationToken).ConfigureAwait(false); } private async ValueTask ExecuteAsync( @@ -270,12 +270,12 @@ private async ValueTask ExecuteAsync( if (typeof(T) == typeof(int)) { - int result = await new ValueTask(pendingOperation, pendingOperation.Token); + int result = await new ValueTask(pendingOperation, pendingOperation.Token).ConfigureAwait(false); return (T)(object)result; } else { - object? result = await new ValueTask(pendingOperation, pendingOperation.Token); + object? result = await new ValueTask(pendingOperation, pendingOperation.Token).ConfigureAwait(false); return (T)result!; } } diff --git a/src/Tmds.Ssh/SftpClient.cs b/src/Tmds.Ssh/SftpClient.cs index ea1aeef..726eb0e 100644 --- a/src/Tmds.Ssh/SftpClient.cs +++ b/src/Tmds.Ssh/SftpClient.cs @@ -81,35 +81,35 @@ public ValueTask OpenOrCreateFileAsync(string path, FileAccess access, => OpenOrCreateFileAsync(path, access, OpenMode.None, cancellationToken); public async ValueTask OpenOrCreateFileAsync(string path, FileAccess access, OpenMode mode, CancellationToken cancellationToken = default) - => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.OpenOrCreate, access, mode), permissions: DefaultCreateFilePermissions, cancellationToken) + => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.OpenOrCreate, access, mode), permissions: DefaultCreateFilePermissions, cancellationToken).ConfigureAwait(false) ?? throw new SftpException(SftpError.NoSuchFile); public ValueTask CreateNewFileAsync(string path, FileAccess access, CancellationToken cancellationToken = default) => CreateNewFileAsync(path, access, OpenMode.None, cancellationToken); public async ValueTask CreateNewFileAsync(string path, FileAccess access, OpenMode mode, CancellationToken cancellationToken = default) - => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.CreateNew, access, mode), permissions: DefaultCreateFilePermissions, cancellationToken) + => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.CreateNew, access, mode), permissions: DefaultCreateFilePermissions, cancellationToken).ConfigureAwait(false) ?? throw new SftpException(SftpError.NoSuchFile); public ValueTask OpenOrCreateFileAsync(string path, FileAccess access, UnixFilePermissions createPermissions, CancellationToken cancellationToken = default) => OpenOrCreateFileAsync(path, access, OpenMode.None, createPermissions, cancellationToken); public async ValueTask OpenOrCreateFileAsync(string path, FileAccess access, OpenMode mode, UnixFilePermissions createPermissions, CancellationToken cancellationToken = default) - => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.OpenOrCreate, access, mode), createPermissions, cancellationToken) + => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.OpenOrCreate, access, mode), createPermissions, cancellationToken).ConfigureAwait(false) ?? throw new SftpException(SftpError.NoSuchFile); public ValueTask CreateNewFileAsync(string path, FileAccess access, UnixFilePermissions permissions, CancellationToken cancellationToken = default) => CreateNewFileAsync(path, access, OpenMode.None, permissions, cancellationToken); public async ValueTask CreateNewFileAsync(string path, FileAccess access, OpenMode mode, UnixFilePermissions permissions, CancellationToken cancellationToken = default) - => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.CreateNew, access, mode), permissions, cancellationToken) + => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.CreateNew, access, mode), permissions, cancellationToken).ConfigureAwait(false) ?? throw new SftpException(SftpError.NoSuchFile); public ValueTask OpenFileAsync(string path, FileAccess access, CancellationToken cancellationToken = default) => OpenFileAsync(path, access, OpenMode.None, cancellationToken); public async ValueTask OpenFileAsync(string path, FileAccess access, OpenMode mode, CancellationToken cancellationToken = default) - => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.Open, access, mode), permissions: DefaultCreateFilePermissions, cancellationToken); + => await OpenFileCoreAsync(path, GetOpenFlags(SftpOpenFlags.Open, access, mode), permissions: DefaultCreateFilePermissions, cancellationToken).ConfigureAwait(false); private SftpOpenFlags GetOpenFlags(SftpOpenFlags flags, FileAccess access, OpenMode mode) { @@ -141,7 +141,7 @@ private SftpOpenFlags GetOpenFlags(SftpOpenFlags flags, FileAccess access, OpenM return ExecuteAsync(packet, id, pendingOperation, cancellationToken); } - public ValueTask DeleteFileAsync(string path, CancellationToken cancellationToken = default) + public async ValueTask DeleteFileAsync(string path, CancellationToken cancellationToken = default) { PacketType packetType = PacketType.SSH_FXP_REMOVE; @@ -152,10 +152,10 @@ public ValueTask DeleteFileAsync(string path, CancellationToken cancellationToke packet.WriteInt(id); packet.WriteString(path); - return ExecuteAsync(packet, id, pendingOperation, cancellationToken); + await ExecuteAsync(packet, id, pendingOperation, cancellationToken).ConfigureAwait(false); } - public ValueTask DeleteDirectoryAsync(string path, CancellationToken cancellationToken = default) + public async ValueTask DeleteDirectoryAsync(string path, CancellationToken cancellationToken = default) { PacketType packetType = PacketType.SSH_FXP_RMDIR; @@ -166,10 +166,10 @@ public ValueTask DeleteDirectoryAsync(string path, CancellationToken cancellatio packet.WriteInt(id); packet.WriteString(path); - return ExecuteAsync(packet, id, pendingOperation, cancellationToken); + await ExecuteAsync(packet, id, pendingOperation, cancellationToken).ConfigureAwait(false); } - public ValueTask RenameAsync(string oldPath, string newPath, CancellationToken cancellationToken = default) + public async ValueTask RenameAsync(string oldPath, string newPath, CancellationToken cancellationToken = default) { PacketType packetType = PacketType.SSH_FXP_RENAME; @@ -181,10 +181,10 @@ public ValueTask RenameAsync(string oldPath, string newPath, CancellationToken c packet.WriteString(oldPath); packet.WriteString(newPath); - return ExecuteAsync(packet, id, pendingOperation, cancellationToken); + await ExecuteAsync(packet, id, pendingOperation, cancellationToken).ConfigureAwait(false); } - public ValueTask GetAttributesAsync(string path, bool followLinks = true, CancellationToken cancellationToken = default) + public async ValueTask GetAttributesAsync(string path, bool followLinks = true, CancellationToken cancellationToken = default) { PacketType packetType = followLinks ? PacketType.SSH_FXP_STAT : PacketType.SSH_FXP_LSTAT; @@ -195,10 +195,10 @@ public ValueTask RenameAsync(string oldPath, string newPath, CancellationToken c packet.WriteInt(id); packet.WriteString(path); - return ExecuteAsync(packet, id, pendingOperation, cancellationToken); + return await ExecuteAsync(packet, id, pendingOperation, cancellationToken).ConfigureAwait(false); } - public ValueTask GetLinkTargetAsync(string linkPath, CancellationToken cancellationToken = default) + public async ValueTask GetLinkTargetAsync(string linkPath, CancellationToken cancellationToken = default) { PacketType packetType = PacketType.SSH_FXP_READLINK; @@ -209,10 +209,10 @@ public ValueTask GetLinkTargetAsync(string linkPath, CancellationToken c packet.WriteInt(id); packet.WriteString(linkPath); - return ExecuteAsync(packet, id, pendingOperation, cancellationToken); + return await ExecuteAsync(packet, id, pendingOperation, cancellationToken).ConfigureAwait(false); } - public ValueTask GetFullPathAsync(string path, CancellationToken cancellationToken = default) + public async ValueTask GetFullPathAsync(string path, CancellationToken cancellationToken = default) { PacketType packetType = PacketType.SSH_FXP_REALPATH; @@ -223,13 +223,13 @@ public ValueTask GetFullPathAsync(string path, CancellationToken cancell packet.WriteInt(id); packet.WriteString(path); - return ExecuteAsync(packet, id, pendingOperation, cancellationToken); + return await ExecuteAsync(packet, id, pendingOperation, cancellationToken).ConfigureAwait(false); } public ValueTask CreateSymbolicLinkAsync(string linkPath, string targetPath, CancellationToken cancellationToken = default) => CreateSymbolicLinkAsync(linkPath, targetPath, overwrite: false, cancellationToken); - private ValueTask CreateSymbolicLinkAsync(string linkPath, string targetPath, bool overwrite, CancellationToken cancellationToken) + private async ValueTask CreateSymbolicLinkAsync(string linkPath, string targetPath, bool overwrite, CancellationToken cancellationToken) { int id; Packet packet; @@ -256,7 +256,7 @@ private ValueTask CreateSymbolicLinkAsync(string linkPath, string targetPath, bo packet.WriteString(targetPath); packet.WriteString(linkPath); - return ExecuteAsync(packet, id, pendingOperation, cancellationToken); + await ExecuteAsync(packet, id, pendingOperation, cancellationToken).ConfigureAwait(false); } public IAsyncEnumerable<(string Path, FileEntryAttributes Attributes)> GetDirectoryEntriesAsync(string path, EnumerationOptions? options = null) @@ -297,12 +297,12 @@ public async ValueTask CreateDirectoryAsync(string path, bool createParents, Uni try { - await mkdir; - await IsDirectory(checkExists); + await mkdir.ConfigureAwait(false); + await IsDirectory(checkExists).ConfigureAwait(false); } catch (SftpException ex) when (ex.Error == SftpError.Failure) { - if (await IsDirectory(checkExists)) + if (await IsDirectory(checkExists).ConfigureAwait(false)) { return; } @@ -314,7 +314,7 @@ async ValueTask IsDirectory(ValueTask checkExists) { try { - FileEntryAttributes? attributes = await checkExists; + FileEntryAttributes? attributes = await checkExists.ConfigureAwait(false); return attributes?.FileType == UnixFileType.Directory; } catch @@ -333,23 +333,28 @@ public ValueTask CreateNewDirectoryAsync(string path, UnixFilePermissions permis public ValueTask CreateNewDirectoryAsync(string path, bool createParents, CancellationToken cancellationToken = default) => CreateNewDirectoryAsync(path, createParents, permissions: DefaultCreateDirectoryPermissions, cancellationToken); - public ValueTask CreateNewDirectoryAsync(string path, bool createParents, UnixFilePermissions permissions, CancellationToken cancellationToken = default) + public async ValueTask CreateNewDirectoryAsync(string path, bool createParents, UnixFilePermissions permissions, CancellationToken cancellationToken = default) { if (createParents) + { + CreateParents(path); + } + + await CreateNewDirectory(path.AsSpan(), awaitable: true, permissions, cancellationToken).ConfigureAwait(false); + + void CreateParents(string path) { ReadOnlySpan span = RemotePath.TrimEndingDirectorySeparators(path); int offset = 1; - int idx = 0; + int idx; while ((idx = span.Slice(offset).IndexOf(RemotePath.DirectorySeparatorChar)) != -1) { offset += idx; // note: parent directories are created using the default permissions, not the permissions arg. - _ = CreateNewDirectoryAsync(span.Slice(0, offset), awaitable: false, permissions: DefaultCreateDirectoryPermissions, cancellationToken: default); + _ = CreateNewDirectory(span.Slice(0, offset), awaitable: false, permissions: DefaultCreateDirectoryPermissions, cancellationToken: default); offset++; } } - - return CreateNewDirectoryAsync(path.AsSpan(), awaitable: true, permissions, cancellationToken); } public ValueTask UploadDirectoryEntriesAsync(string localDirPath, string remoteDirPath, CancellationToken cancellationToken = default) @@ -410,7 +415,7 @@ public async ValueTask UploadDirectoryEntriesAsync(string localDirPath, string r { if (onGoing.Count == MaxConcurrentOperations) { - await onGoing.Dequeue(); + await onGoing.Dequeue().ConfigureAwait(false); } switch (item.Type) { @@ -454,7 +459,7 @@ public async ValueTask UploadDirectoryEntriesAsync(string localDirPath, string r } while (onGoing.TryDequeue(out ValueTask pending)) { - await pending; + await pending.ConfigureAwait(false); } } finally @@ -463,7 +468,7 @@ public async ValueTask UploadDirectoryEntriesAsync(string localDirPath, string r { try { - await pending; + await pending.ConfigureAwait(false); } catch { } @@ -518,7 +523,7 @@ private async ValueTask UploadFileAsync(string localPath, string remotePath, lon permissions ??= GetPermissionsForFile(localFile); - using SftpFile remoteFile = (await OpenFileCoreAsync(remotePath, (overwrite ? SftpOpenFlags.OpenOrCreate : SftpOpenFlags.CreateNew) | SftpOpenFlags.Write, permissions.Value, cancellationToken))!; + using SftpFile remoteFile = (await OpenFileCoreAsync(remotePath, (overwrite ? SftpOpenFlags.OpenOrCreate : SftpOpenFlags.CreateNew) | SftpOpenFlags.Write, permissions.Value, cancellationToken).ConfigureAwait(false))!; length ??= RandomAccess.GetLength(localFile); @@ -528,13 +533,13 @@ private async ValueTask UploadFileAsync(string localPath, string remotePath, lon { // Obtain a buffer before starting the copy to ensure we're not competing // for buffers with the previous copy. - await s_uploadBufferSemaphore.WaitAsync(cancellationToken); + await s_uploadBufferSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); previous = CopyBuffer(previous, offset, GetMaxWritePayload(remoteFile.Handle)); } - await previous; + await previous.ConfigureAwait(false); - await remoteFile.CloseAsync(cancellationToken); + await remoteFile.CloseAsync(cancellationToken).ConfigureAwait(false); async ValueTask CopyBuffer(ValueTask previousCopy, long offset, int length) { @@ -549,12 +554,12 @@ async ValueTask CopyBuffer(ValueTask previousCopy, long offset, int length) { break; } - await remoteFile.WriteAtAsync(buffer.AsMemory(0, bytesRead), offset, cancellationToken); + await remoteFile.WriteAtAsync(buffer.AsMemory(0, bytesRead), offset, cancellationToken).ConfigureAwait(false); length -= bytesRead; offset += bytesRead; } while (length > 0); - await previousCopy; + await previousCopy.ConfigureAwait(false); } finally { @@ -620,11 +625,11 @@ public async ValueTask DownloadDirectoryEntriesAsync(string remoteDirPath, strin var onGoing = new Queue(); try { - await foreach (var item in fse.WithCancellation(cancellationToken)) + await foreach (var item in fse.WithCancellation(cancellationToken).ConfigureAwait(false)) { if (onGoing.Count == MaxConcurrentOperations) { - await onGoing.Dequeue(); + await onGoing.Dequeue().ConfigureAwait(false); } switch (item.Type) { @@ -654,7 +659,7 @@ public async ValueTask DownloadDirectoryEntriesAsync(string remoteDirPath, strin } while (onGoing.TryDequeue(out ValueTask pending)) { - await pending; + await pending.ConfigureAwait(false); } } finally @@ -663,7 +668,7 @@ public async ValueTask DownloadDirectoryEntriesAsync(string remoteDirPath, strin { try { - await pending; + await pending.ConfigureAwait(false); } catch { } @@ -734,7 +739,7 @@ private async ValueTask DownloadLinkAsync(string remotePath, string localPath, b } // note: the remote server is expected to return a path that has forward slashes, also when that server runs on Windows. - string targetPath = await GetLinkTargetAsync(remotePath, cancellationToken); + string targetPath = await GetLinkTargetAsync(remotePath, cancellationToken).ConfigureAwait(false); if (exists) { File.Delete(localPath); @@ -752,7 +757,7 @@ private async ValueTask DownloadFileAsync(string remotePath, string localPath, l { ValueTask getAttributes = length == null || permissions == null ? GetAttributesAsync(remotePath, followLinks: true) : default; - using SftpFile? remoteFile = await OpenFileAsync(remotePath, FileAccess.Read, cancellationToken); + using SftpFile? remoteFile = await OpenFileAsync(remotePath, FileAccess.Read, cancellationToken).ConfigureAwait(false); if (remoteFile is null) { return; @@ -760,7 +765,7 @@ private async ValueTask DownloadFileAsync(string remotePath, string localPath, l if (length == null || permissions == null) { - FileEntryAttributes? attributes = await getAttributes; + FileEntryAttributes? attributes = await getAttributes.ConfigureAwait(false); if (attributes is null) { throw new SftpException(SftpError.NoSuchFile); @@ -777,13 +782,13 @@ private async ValueTask DownloadFileAsync(string remotePath, string localPath, l { // Obtain a buffer before starting the copy to ensure we're not competing // for buffers with the previous copy. - await s_downloadBufferSemaphore.WaitAsync(cancellationToken); + await s_downloadBufferSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); previous = CopyBuffer(previous, offset, MaxReadPayload); } - await previous; + await previous.ConfigureAwait(false); - await remoteFile.CloseAsync(cancellationToken); + await remoteFile.CloseAsync(cancellationToken).ConfigureAwait(false); async ValueTask CopyBuffer(ValueTask previousCopy, long offset, int length) { @@ -793,7 +798,7 @@ async ValueTask CopyBuffer(ValueTask previousCopy, long offset, int length) buffer = ArrayPool.Shared.Rent(length); do { - int bytesRead = await remoteFile.ReadAtAsync(buffer, offset, cancellationToken); + int bytesRead = await remoteFile.ReadAtAsync(buffer, offset, cancellationToken).ConfigureAwait(false); if (bytesRead == 0) { break; @@ -803,7 +808,7 @@ async ValueTask CopyBuffer(ValueTask previousCopy, long offset, int length) offset += bytesRead; } while (length > 0); - await previousCopy; + await previousCopy.ConfigureAwait(false); } finally { @@ -816,7 +821,7 @@ async ValueTask CopyBuffer(ValueTask previousCopy, long offset, int length) } } - private ValueTask CreateNewDirectoryAsync(ReadOnlySpan path, bool awaitable, UnixFilePermissions permissions, CancellationToken cancellationToken) + private ValueTask CreateNewDirectory(ReadOnlySpan path, bool awaitable, UnixFilePermissions permissions, CancellationToken cancellationToken) { PacketType packetType = PacketType.SSH_FXP_MKDIR; @@ -835,9 +840,9 @@ internal async Task ProtocolInitAsync(CancellationToken cancellationToken) { using Packet packet = new Packet(PacketType.SSH_FXP_INIT); packet.WriteUInt(ProtocolVersion); - await _channel.WriteAsync(packet.Data, cancellationToken); + await _channel.WriteAsync(packet.Data, cancellationToken).ConfigureAwait(false); - ReadOnlyMemory versionPacket = await ReadPacketAsync(cancellationToken); + ReadOnlyMemory versionPacket = await ReadPacketAsync(cancellationToken).ConfigureAwait(false); HandleVersionPacket(versionPacket.Span); _ = ReadAllPacketsAsync(); @@ -877,7 +882,7 @@ private async ValueTask> ReadPacketAsync(CancellationToken do { Memory readBuffer = new Memory(_packetBuffer, totalReceived, 4 - totalReceived); - (ChannelReadType type, int bytesRead) = await _channel.ReadAsync(readBuffer, default, cancellationToken); + (ChannelReadType type, int bytesRead) = await _channel.ReadAsync(readBuffer, default, cancellationToken).ConfigureAwait(false); if (type != ChannelReadType.StandardOutput) { throw new InvalidDataException($"Unexpected data type: {type}"); @@ -904,7 +909,7 @@ private async ValueTask> ReadPacketAsync(CancellationToken while (totalReceived < totalReceiveLength) { Memory readBuffer = new Memory(_packetBuffer, totalReceived, totalReceiveLength - totalReceived); - (ChannelReadType type, int bytesRead) = await _channel.ReadAsync(readBuffer, default, cancellationToken); + (ChannelReadType type, int bytesRead) = await _channel.ReadAsync(readBuffer, default, cancellationToken).ConfigureAwait(false); if (type != ChannelReadType.StandardOutput) { throw new InvalidDataException($"Unexpected data type: {type}"); @@ -917,13 +922,13 @@ private async ValueTask> ReadPacketAsync(CancellationToken private async Task SendPacketsAsync() { bool sendPackets = true; - await foreach (Packet packet in _pendingSends.Reader.ReadAllAsync()) + await foreach (Packet packet in _pendingSends.Reader.ReadAllAsync().ConfigureAwait(false)) { if (sendPackets) { try { - await _channel.WriteAsync(packet.Data); + await _channel.WriteAsync(packet.Data).ConfigureAwait(false); } catch { @@ -941,7 +946,7 @@ private async Task ReadAllPacketsAsync() { do { - ReadOnlyMemory packet = await ReadPacketAsync(cancellationToken: default); + ReadOnlyMemory packet = await ReadPacketAsync(cancellationToken: default).ConfigureAwait(false); if (packet.Length == 0) { break; @@ -1044,7 +1049,7 @@ private async ValueTask WriteFileMultiAsync(byte[] handle, long offset, ReadOnly { int writeLength = Math.Min(buffer.Length, GetMaxWritePayload(handle)); - await WriteFileSingleAsync(handle, offset, buffer.Slice(0, writeLength), cancellationToken); + await WriteFileSingleAsync(handle, offset, buffer.Slice(0, writeLength), cancellationToken).ConfigureAwait(false); buffer = buffer.Slice(writeLength); offset += writeLength; diff --git a/src/Tmds.Ssh/SftpFile.cs b/src/Tmds.Ssh/SftpFile.cs index c6ff0b5..b31057d 100644 --- a/src/Tmds.Ssh/SftpFile.cs +++ b/src/Tmds.Ssh/SftpFile.cs @@ -68,7 +68,7 @@ public override async ValueTask ReadAsync(Memory buffer, Cancellation int bytesRead = 0; try { - bytesRead = await _client.ReadFileAsync(Handle, readOffset, buffer, cancellationToken); + bytesRead = await _client.ReadFileAsync(Handle, readOffset, buffer, cancellationToken).ConfigureAwait(false); return bytesRead; } @@ -78,11 +78,11 @@ public override async ValueTask ReadAsync(Memory buffer, Cancellation } } - public ValueTask ReadAtAsync(Memory buffer, long offset, CancellationToken cancellationToken = default) + public async ValueTask ReadAtAsync(Memory buffer, long offset, CancellationToken cancellationToken = default) { ThrowIfDisposed(); - return _client.ReadFileAsync(Handle, offset, buffer, cancellationToken); + return await _client.ReadFileAsync(Handle, offset, buffer, cancellationToken).ConfigureAwait(false); } public override void Write(byte[] buffer, int offset, int count) @@ -98,7 +98,7 @@ public async override ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella long writeOffset = Interlocked.Add(ref _position, buffer.Length) - buffer.Length; try { - await _client.WriteFileAsync(Handle, writeOffset, buffer, cancellationToken); + await _client.WriteFileAsync(Handle, writeOffset, buffer, cancellationToken).ConfigureAwait(false); } catch { @@ -107,18 +107,18 @@ public async override ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella } } - public ValueTask WriteAtAsync(ReadOnlyMemory buffer, long offset, CancellationToken cancellationToken = default) + public async ValueTask WriteAtAsync(ReadOnlyMemory buffer, long offset, CancellationToken cancellationToken = default) { ThrowIfDisposed(); - return _client.WriteFileAsync(Handle, offset, buffer, cancellationToken); + await _client.WriteFileAsync(Handle, offset, buffer, cancellationToken).ConfigureAwait(false); } - public ValueTask GetAttributesAsync(CancellationToken cancellationToken = default) + public async ValueTask GetAttributesAsync(CancellationToken cancellationToken = default) { ThrowIfDisposed(); - return _client.GetAttributesForHandleAsync(Handle, cancellationToken); + return await _client.GetAttributesForHandleAsync(Handle, cancellationToken).ConfigureAwait(false); } private void ThrowIfDisposed() @@ -129,12 +129,12 @@ private void ThrowIfDisposed() } } - public ValueTask CloseAsync(CancellationToken cancellationToken = default) + public async ValueTask CloseAsync(CancellationToken cancellationToken = default) { ThrowIfDisposed(); _disposed = true; - return _client.CloseFileAsync(Handle, cancellationToken); + await _client.CloseFileAsync(Handle, cancellationToken).ConfigureAwait(false); } protected override void Dispose(bool disposing) diff --git a/src/Tmds.Ssh/SftpFileSystemEnumerable.cs b/src/Tmds.Ssh/SftpFileSystemEnumerable.cs index cb12f7c..c74440a 100644 --- a/src/Tmds.Ssh/SftpFileSystemEnumerable.cs +++ b/src/Tmds.Ssh/SftpFileSystemEnumerable.cs @@ -110,12 +110,12 @@ public async ValueTask MoveNextAsync() return true; } if (linkPath is not null && - await ReadLinkTargetEntry(linkPath, linkEntry)) + await ReadLinkTargetEntry(linkPath, linkEntry).ConfigureAwait(false)) { return true; } } - } while (await TryReadNewBufferAsync()); + } while (await TryReadNewBufferAsync().ConfigureAwait(false)); _entriesRemaining = Complete; return false; @@ -138,7 +138,7 @@ private async ValueTask TryReadNewBufferAsync() } } - await ReadNewBufferAsync(); + await ReadNewBufferAsync().ConfigureAwait(false); return true; } @@ -146,13 +146,13 @@ private async ValueTask ReadNewBufferAsync() { if (_directoryHandle is null) { - _directoryHandle = await _client.OpenDirectoryAsync(_path, _cancellationToken); + _directoryHandle = await _client.OpenDirectoryAsync(_path, _cancellationToken).ConfigureAwait(false); _readAhead = _client.ReadDirAsync(_directoryHandle, _cancellationToken); } const int CountIndex = 4 /* packet length */ + 1 /* packet type */ + 4 /* id */; - _readDirPacket = await _readAhead; + _readDirPacket = await _readAhead.ConfigureAwait(false); if (_readDirPacket.Length < CountIndex + 4) { @@ -218,7 +218,7 @@ private bool SetCurrent(ref SftpFileEntry entry) private async Task ReadLinkTargetEntry(string linkPath, Memory linkEntry) { - FileEntryAttributes? attributes = await _client.GetAttributesAsync(linkPath, followLinks: true, _cancellationToken); + FileEntryAttributes? attributes = await _client.GetAttributesAsync(linkPath, followLinks: true, _cancellationToken).ConfigureAwait(false); if (attributes is not null) { if ((!_followDirectoryLinks && attributes.FileType == UnixFileType.Directory) || diff --git a/src/Tmds.Ssh/SshClient.cs b/src/Tmds.Ssh/SshClient.cs index 6145c8e..0c06c76 100644 --- a/src/Tmds.Ssh/SshClient.cs +++ b/src/Tmds.Ssh/SshClient.cs @@ -535,7 +535,7 @@ public async Task CreateSftpClientAsync(CancellationToken cancellati try { - await sftpClient.ProtocolInitAsync(cancellationToken); + await sftpClient.ProtocolInitAsync(cancellationToken).ConfigureAwait(false); } catch {