A class representing the attributes of a file or directory on the server. It may be used to specify new attributes, or to query existing attributes.
F_SIZE | = | 0x00000001 |
F_UIDGID | = | 0x00000002 |
F_PERMISSIONS | = | 0x00000004 |
F_ACMODTIME | = | 0x00000008 |
F_EXTENDED | = | 0x80000000 |
[RW] | atime | |
[RW] | extended | |
[RW] | gid | |
[RW] | mtime | |
[RW] | permissions | |
[RW] | size | |
[RW] | uid |
Returns the buffer factory for this class.
[ show source ]
# File lib/net/sftp/protocol/01/attributes.rb, line 48 48: def self.buffers 49: @buffers 50: end
Create a new, empty Attributes object.
[ show source ]
# File lib/net/sftp/protocol/01/attributes.rb, line 58 58: def self.empty 59: new 60: end
Create a new Attributes object, initialized from the given buffer.
[ show source ]
# File lib/net/sftp/protocol/01/attributes.rb, line 63 63: def self.from_buffer( buffer ) 64: flags = buffer.read_long 65: 66: size = buffer.read_int64 if ( flags & F_SIZE ) != 0 67: uid = buffer.read_long if ( flags & F_UIDGID ) != 0 68: gid = buffer.read_long if ( flags & F_UIDGID ) != 0 69: permissions = buffer.read_long if ( flags & F_PERMISSIONS ) != 0 70: atime = buffer.read_long if ( flags & F_ACMODTIME ) != 0 71: mtime = buffer.read_long if ( flags & F_ACMODTIME ) != 0 72: 73: if ( flags & F_EXTENDED ) != 0 74: extended = Hash.new 75: buffer.read_long.times do 76: extended[ buffer.read_string ] = buffer.read_string 77: end 78: end 79: 80: new( size, uid, gid, permissions, atime, mtime, extended ) 81: end
Create a new attributes object, initialized from the given hash. The :owner and :group attributes are treated specially; they are not actually supported by this version of the protocol, but are instead converted by this method to their corresponding id numbers, and assigned (respectively) to :uid and :gid.
[ show source ]
# File lib/net/sftp/protocol/01/attributes.rb, line 88 88: def self.from_hash( hash ) 89: if hash[:owner] 90: require 'etc' 91: hash[:uid] = Etc.getpwnam( hash[:owner] ).uid 92: end 93: 94: if hash[:group] 95: require 'etc' 96: hash[:gid] = Etc.getgrnam( hash[:group] ).gid 97: end 98: 99: new hash[:size], hash[:uid], hash[:gid], hash[:permissions], 100: hash[:atime], hash[:mtime], hash[:extended] 101: end
An initialization routine, to grant the class (factory) access to a buffer factory. The buffer factory is used by the class’ to_s method to encode the object’s attributes.
This returns self, making it suitable for chaining.
[ show source ]
# File lib/net/sftp/protocol/01/attributes.rb, line 42 42: def self.init( buffers ) 43: @buffers = buffers 44: self 45: end
Create a new Attributes with the given attributes.
[ show source ]
# File lib/net/sftp/protocol/01/attributes.rb, line 106 106: def initialize( size=nil, uid=nil, gid=nil, permissions=nil, 107: atime=nil, mtime=nil, extended=nil ) 108: # begin 109: @size = size 110: @uid = uid 111: @gid = gid 112: @permissions = permissions 113: @atime = atime 114: @mtime = mtime 115: @extended = extended 116: end
Returns the buffer factory for the object’s class.
[ show source ]
# File lib/net/sftp/protocol/01/attributes.rb, line 53 53: def buffers 54: self.class.buffers 55: end
Convert the object to a string suitable for passing in an SFTP packet.
[ show source ]
# File lib/net/sftp/protocol/01/attributes.rb, line 120 120: def to_s 121: flags = 0 122: 123: flags |= F_SIZE if @size 124: flags |= F_UIDGID if @uid && @gid 125: flags |= F_PERMISSIONS if @permissions 126: flags |= F_ACMODTIME if @atime && @mtime 127: flags |= F_EXTENDED if @extended 128: 129: buffer = buffers.writer 130: buffer.write_long flags 131: buffer.write_int64 @size if @size 132: buffer.write_long @uid, @gid if @uid && @gid 133: buffer.write_long @permissions if @permissions 134: buffer.write_long @atime, @mtime if @atime && @mtime 135: 136: if @extended 137: buffer.write_long @extended.size 138: @extended.each { |k,v| buffer.write_string k, v } 139: end 140: 141: buffer.to_s 142: end