UniversalTime: correctly set the flags.

When a timestamp is set/unset the flags should reflect this.
This commit is contained in:
Robert Haines 2019-10-27 10:29:27 +00:00
parent d3027eab95
commit b58b97fe23
1 changed files with 25 additions and 6 deletions

View File

@ -4,24 +4,43 @@ module Zip
HEADER_ID = 'UT'
register_map
ATIME_MASK = 0b010
CTIME_MASK = 0b100
MTIME_MASK = 0b001
def initialize(binstr = nil)
@ctime = nil
@mtime = nil
@atime = nil
@flag = nil
@flag = 0
binstr && merge(binstr)
end
attr_accessor :atime, :ctime, :mtime, :flag
attr_reader :atime, :ctime, :mtime, :flag
def atime=(time)
@flag = time.nil? ? @flag & ~ATIME_MASK : @flag | ATIME_MASK
@atime = time
end
def ctime=(time)
@flag = time.nil? ? @flag & ~CTIME_MASK : @flag | CTIME_MASK
@ctime = time
end
def mtime=(time)
@flag = time.nil? ? @flag & ~MTIME_MASK : @flag | MTIME_MASK
@mtime = time
end
def merge(binstr)
return if binstr.empty?
size, content = initial_parse(binstr)
size || return
@flag, mtime, atime, ctime = content.unpack('CVVV')
mtime && @mtime ||= ::Zip::DOSTime.at(mtime)
atime && @atime ||= ::Zip::DOSTime.at(atime)
ctime && @ctime ||= ::Zip::DOSTime.at(ctime)
@flag, mt, at, ct = content.unpack('CVVV')
mt && @mtime ||= ::Zip::DOSTime.at(mt)
at && @atime ||= ::Zip::DOSTime.at(at)
ct && @ctime ||= ::Zip::DOSTime.at(ct)
end
def ==(other)