2014-03-10 02:38:14 +08:00
|
|
|
module Zip
|
|
|
|
# Olf Info-ZIP Extra for UNIX uid/gid and file timestampes
|
|
|
|
class ExtraField::OldUnix < ExtraField::Generic
|
2015-03-21 16:27:44 +08:00
|
|
|
HEADER_ID = 'UX'
|
2014-03-10 02:38:14 +08:00
|
|
|
register_map
|
|
|
|
|
|
|
|
def initialize(binstr = nil)
|
|
|
|
@uid = 0
|
|
|
|
@gid = 0
|
|
|
|
@atime = nil
|
|
|
|
@mtime = nil
|
2015-03-21 15:45:46 +08:00
|
|
|
binstr && merge(binstr)
|
2014-03-10 02:38:14 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :uid, :gid, :atime, :mtime
|
|
|
|
|
|
|
|
def merge(binstr)
|
|
|
|
return if binstr.empty?
|
|
|
|
size, content = initial_parse(binstr)
|
|
|
|
# size: 0 for central directory. 4 for local header
|
|
|
|
return if (!size || size == 0)
|
2015-03-21 16:27:44 +08:00
|
|
|
atime, mtime, uid, gid = content.unpack('VVvv')
|
2014-03-10 02:38:14 +08:00
|
|
|
@uid ||= uid
|
|
|
|
@gid ||= gid
|
|
|
|
@atime ||= atime
|
|
|
|
@mtime ||= mtime
|
|
|
|
end
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
@uid == other.uid &&
|
|
|
|
@gid == other.gid &&
|
|
|
|
@atime == other.atime &&
|
|
|
|
@mtime == other.mtime
|
|
|
|
end
|
|
|
|
|
|
|
|
def pack_for_local
|
2015-03-21 16:27:44 +08:00
|
|
|
[@atime, @mtime, @uid, @gid].pack('VVvv')
|
2014-03-10 02:38:14 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def pack_for_c_dir
|
2015-03-21 16:27:44 +08:00
|
|
|
[@atime, @mtime].pack('VV')
|
2014-03-10 02:38:14 +08:00
|
|
|
end
|
|
|
|
end
|
2015-03-21 03:45:50 +08:00
|
|
|
end
|