SftpLinkRequest.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using Renci.SshNet.Sftp.Responses;
  2. using System;
  3. namespace Renci.SshNet.Sftp.Requests
  4. {
  5. internal class SftpLinkRequest : SftpRequest
  6. {
  7. #if TUNING
  8. private byte[] _newLinkPath;
  9. private byte[] _existingPath;
  10. #endif
  11. public override SftpMessageTypes SftpMessageType
  12. {
  13. get { return SftpMessageTypes.Link; }
  14. }
  15. #if TUNING
  16. public string NewLinkPath
  17. {
  18. get { return Utf8.GetString(_newLinkPath, 0, _newLinkPath.Length); }
  19. private set { _newLinkPath = Utf8.GetBytes(value); }
  20. }
  21. #else
  22. public string NewLinkPath { get; private set; }
  23. #endif
  24. #if TUNING
  25. public string ExistingPath
  26. {
  27. get { return Utf8.GetString(_existingPath, 0, _existingPath.Length); }
  28. private set { _existingPath = Utf8.GetBytes(value); }
  29. }
  30. #else
  31. public string ExistingPath { get; private set; }
  32. #endif
  33. public bool IsSymLink { get; private set; }
  34. #if TUNING
  35. /// <summary>
  36. /// Gets the size of the message in bytes.
  37. /// </summary>
  38. /// <value>
  39. /// The size of the messages in bytes.
  40. /// </value>
  41. protected override int BufferCapacity
  42. {
  43. get
  44. {
  45. var capacity = base.BufferCapacity;
  46. capacity += 4; // NewLinkPath length
  47. capacity += NewLinkPath.Length; // NewLinkPath
  48. capacity += 4; // ExistingPath length
  49. capacity += ExistingPath.Length; // ExistingPath
  50. capacity += 1; // IsSymLink
  51. return capacity;
  52. }
  53. }
  54. #endif
  55. /// <summary>
  56. /// Initializes a new instance of the <see cref="SftpLinkRequest" /> class.
  57. /// </summary>
  58. /// <param name="protocolVersion">The protocol version.</param>
  59. /// <param name="requestId">The request id.</param>
  60. /// <param name="newLinkPath">Specifies the path name of the new link to create.</param>
  61. /// <param name="existingPath">Specifies the path of a target object to which the newly created link will refer. In the case of a symbolic link, this path may not exist.</param>
  62. /// <param name="isSymLink">if set to <c>false</c> the link should be a hard link, or a second directory entry referring to the same file or directory object.</param>
  63. /// <param name="statusAction">The status action.</param>
  64. public SftpLinkRequest(uint protocolVersion, uint requestId, string newLinkPath, string existingPath, bool isSymLink, Action<SftpStatusResponse> statusAction)
  65. : base(protocolVersion, requestId, statusAction)
  66. {
  67. this.NewLinkPath = newLinkPath;
  68. this.ExistingPath = existingPath;
  69. this.IsSymLink = isSymLink;
  70. }
  71. protected override void LoadData()
  72. {
  73. base.LoadData();
  74. #if TUNING
  75. _newLinkPath = ReadBinary();
  76. _existingPath = ReadBinary();
  77. #else
  78. this.NewLinkPath = this.ReadString();
  79. this.ExistingPath = this.ReadString();
  80. #endif
  81. this.IsSymLink = this.ReadBoolean();
  82. }
  83. protected override void SaveData()
  84. {
  85. base.SaveData();
  86. #if TUNING
  87. WriteBinaryString(_newLinkPath);
  88. WriteBinaryString(_existingPath);
  89. #else
  90. this.Write(this.NewLinkPath);
  91. this.Write(this.ExistingPath);
  92. #endif
  93. this.Write(this.IsSymLink);
  94. }
  95. }
  96. }