Class: HrrRbSftp::Protocol::Version1::Packet::SSH_FXP_FSETSTAT

Inherits:
Object
  • Object
show all
Includes:
Common::Packetable
Defined in:
lib/hrr_rb_sftp/protocol/version1/packet/010_ssh_fxp_fsetstat.rb

Constant Summary collapse

TYPE =
10
FORMAT =
[
  [DataType::Byte,   :"type"      ],
  [DataType::Uint32, :"request-id"],
  [DataType::String, :"handle"    ],
  [DataType::Attrs,  :"attrs"     ],
]

Instance Attribute Summary

Attributes included from Loggable

#logger

Instance Method Summary collapse

Methods included from Common::Packetable

#decode, #encode, #initialize

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn

Instance Method Details

#respond_to(request) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hrr_rb_sftp/protocol/version1/packet/010_ssh_fxp_fsetstat.rb', line 17

def respond_to request
  begin
    raise "Specified handle does not exist" unless @handles.has_key?(request[:"handle"])
    file = @handles[request[:"handle"]]
    attrs = request[:"attrs"]
    file.chmod(attrs[:"permissions"])                       if attrs.has_key?(:"permissions")
    File.utime(attrs[:"atime"], attrs[:"mtime"], file.path) if attrs.has_key?(:"atime") && attrs.has_key?(:"mtime")
    file.chown(attrs[:"uid"], attrs[:"gid"])                if attrs.has_key?(:"uid") && attrs.has_key?(:"gid")
    file.truncate(attrs[:"size"])                           if attrs.has_key?(:"size")
    {
      :"type"          => SSH_FXP_STATUS::TYPE,
      :"request-id"    => request[:"request-id"],
      :"code"          => SSH_FXP_STATUS::SSH_FX_OK,
      :"error message" => "Success",
      :"language tag"  => "",
    }
  rescue => e
    log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
    {
      :"type"          => SSH_FXP_STATUS::TYPE,
      :"request-id"    => request[:"request-id"],
      :"code"          => SSH_FXP_STATUS::SSH_FX_FAILURE,
      :"error message" => e.message,
      :"language tag"  => "",
    }
  end
end