Skip to content

Fix SftpFileAttributes file type detection #1688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions src/Renci.SshNet/Sftp/Requests/SftpMkDirRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Renci.SshNet.Sftp.Requests
internal sealed class SftpMkDirRequest : SftpRequest
{
private byte[] _path;
private byte[] _attributesBytes;

public override SftpMessageTypes SftpMessageType
{
Expand All @@ -23,18 +22,6 @@ public string Path

public Encoding Encoding { get; private set; }

private SftpFileAttributes Attributes { get; set; }

private byte[] AttributesBytes
{
get
{
_attributesBytes ??= Attributes.GetBytes();

return _attributesBytes;
}
}

/// <summary>
/// Gets the size of the message in bytes.
/// </summary>
Expand All @@ -48,36 +35,30 @@ protected override int BufferCapacity
var capacity = base.BufferCapacity;
capacity += 4; // Path length
capacity += _path.Length; // Path
capacity += AttributesBytes.Length; // Attributes
capacity += 4; // Attributes
return capacity;
}
}

public SftpMkDirRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, Action<SftpStatusResponse> statusAction)
: this(protocolVersion, requestId, path, encoding, SftpFileAttributes.Empty, statusAction)
{
}

private SftpMkDirRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, SftpFileAttributes attributes, Action<SftpStatusResponse> statusAction)
: base(protocolVersion, requestId, statusAction)
{
Encoding = encoding;
Path = path;
Attributes = attributes;
}

protected override void LoadData()
{
base.LoadData();
_path = ReadBinary();
Attributes = ReadAttributes();
_ = ReadAttributes();
}

protected override void SaveData()
{
base.SaveData();
WriteBinaryString(_path);
Write(AttributesBytes);
Write(0u); // empty attributes
}
}
}
17 changes: 2 additions & 15 deletions src/Renci.SshNet/Sftp/Requests/SftpOpenRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ internal sealed class SftpOpenRequest : SftpRequest
{
private readonly Action<SftpHandleResponse> _handleAction;
private byte[] _fileName;
private byte[] _attributes;

public override SftpMessageTypes SftpMessageType
{
Expand All @@ -24,12 +23,6 @@ public string Filename

public Flags Flags { get; }

public SftpFileAttributes Attributes
{
get { return SftpFileAttributes.FromBytes(_attributes); }
private set { _attributes = value.GetBytes(); }
}

public Encoding Encoding { get; }

/// <summary>
Expand All @@ -46,23 +39,17 @@ protected override int BufferCapacity
capacity += 4; // FileName length
capacity += _fileName.Length; // FileName
capacity += 4; // Flags
capacity += _attributes.Length; // Attributes
capacity += 4; // Attributes
return capacity;
}
}

public SftpOpenRequest(uint protocolVersion, uint requestId, string fileName, Encoding encoding, Flags flags, Action<SftpHandleResponse> handleAction, Action<SftpStatusResponse> statusAction)
: this(protocolVersion, requestId, fileName, encoding, flags, SftpFileAttributes.Empty, handleAction, statusAction)
{
}

private SftpOpenRequest(uint protocolVersion, uint requestId, string fileName, Encoding encoding, Flags flags, SftpFileAttributes attributes, Action<SftpHandleResponse> handleAction, Action<SftpStatusResponse> statusAction)
: base(protocolVersion, requestId, statusAction)
{
Encoding = encoding;
Filename = fileName;
Flags = flags;
Attributes = attributes;

_handleAction = handleAction;
}
Expand All @@ -79,7 +66,7 @@ protected override void SaveData()

WriteBinaryString(_fileName);
Write((uint)Flags);
Write(_attributes);
Write(0u); // empty attributes
}

public override void Complete(SftpResponse response)
Expand Down
8 changes: 4 additions & 4 deletions src/Renci.SshNet/Sftp/Responses/SftpVersionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public override SftpMessageTypes SftpMessageType

public uint Version { get; set; }

public IDictionary<string, string> Extentions { get; set; }
public IDictionary<string, string> Extensions { get; set; }

protected override void LoadData()
{
base.LoadData();

Version = ReadUInt32();
Extentions = ReadExtensionPair();
Extensions = ReadExtensionPair();
}

protected override void SaveData()
Expand All @@ -27,9 +27,9 @@ protected override void SaveData()

Write(Version);

if (Extentions != null)
if (Extensions != null)
{
Write(Extentions);
Write(Extensions);
}
}
}
Expand Down
Loading
Loading