rubyzip/lib/zip/extra_field/old_unix.rb

49 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
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?
2014-03-10 02:38:14 +08:00
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 # rubocop:disable Naming/MemoizedInstanceVariableName
2014-03-10 02:38:14 +08:00
end
def ==(other)
@uid == other.uid &&
@gid == other.gid &&
@atime == other.atime &&
@mtime == other.mtime
2014-03-10 02:38:14 +08:00
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
end