UniversalTime: correctly set the flags.
When a timestamp is set/unset the flags should reflect this.
This commit is contained in:
parent
d3027eab95
commit
b58b97fe23
|
@ -4,24 +4,43 @@ module Zip
|
||||||
HEADER_ID = 'UT'
|
HEADER_ID = 'UT'
|
||||||
register_map
|
register_map
|
||||||
|
|
||||||
|
ATIME_MASK = 0b010
|
||||||
|
CTIME_MASK = 0b100
|
||||||
|
MTIME_MASK = 0b001
|
||||||
|
|
||||||
def initialize(binstr = nil)
|
def initialize(binstr = nil)
|
||||||
@ctime = nil
|
@ctime = nil
|
||||||
@mtime = nil
|
@mtime = nil
|
||||||
@atime = nil
|
@atime = nil
|
||||||
@flag = nil
|
@flag = 0
|
||||||
binstr && merge(binstr)
|
binstr && merge(binstr)
|
||||||
end
|
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)
|
def merge(binstr)
|
||||||
return if binstr.empty?
|
return if binstr.empty?
|
||||||
size, content = initial_parse(binstr)
|
size, content = initial_parse(binstr)
|
||||||
size || return
|
size || return
|
||||||
@flag, mtime, atime, ctime = content.unpack('CVVV')
|
@flag, mt, at, ct = content.unpack('CVVV')
|
||||||
mtime && @mtime ||= ::Zip::DOSTime.at(mtime)
|
mt && @mtime ||= ::Zip::DOSTime.at(mt)
|
||||||
atime && @atime ||= ::Zip::DOSTime.at(atime)
|
at && @atime ||= ::Zip::DOSTime.at(at)
|
||||||
ctime && @ctime ||= ::Zip::DOSTime.at(ctime)
|
ct && @ctime ||= ::Zip::DOSTime.at(ct)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
|
|
Loading…
Reference in New Issue