Skip to content

Commit b58b97f

Browse files
committed
UniversalTime: correctly set the flags.
When a timestamp is set/unset the flags should reflect this.
1 parent d3027ea commit b58b97f

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

lib/zip/extra_field/universal_time.rb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,43 @@ class ExtraField::UniversalTime < ExtraField::Generic
44
HEADER_ID = 'UT'
55
register_map
66

7+
ATIME_MASK = 0b010
8+
CTIME_MASK = 0b100
9+
MTIME_MASK = 0b001
10+
711
def initialize(binstr = nil)
812
@ctime = nil
913
@mtime = nil
1014
@atime = nil
11-
@flag = nil
15+
@flag = 0
1216
binstr && merge(binstr)
1317
end
1418

15-
attr_accessor :atime, :ctime, :mtime, :flag
19+
attr_reader :atime, :ctime, :mtime, :flag
20+
21+
def atime=(time)
22+
@flag = time.nil? ? @flag & ~ATIME_MASK : @flag | ATIME_MASK
23+
@atime = time
24+
end
25+
26+
def ctime=(time)
27+
@flag = time.nil? ? @flag & ~CTIME_MASK : @flag | CTIME_MASK
28+
@ctime = time
29+
end
30+
31+
def mtime=(time)
32+
@flag = time.nil? ? @flag & ~MTIME_MASK : @flag | MTIME_MASK
33+
@mtime = time
34+
end
1635

1736
def merge(binstr)
1837
return if binstr.empty?
1938
size, content = initial_parse(binstr)
2039
size || return
21-
@flag, mtime, atime, ctime = content.unpack('CVVV')
22-
mtime && @mtime ||= ::Zip::DOSTime.at(mtime)
23-
atime && @atime ||= ::Zip::DOSTime.at(atime)
24-
ctime && @ctime ||= ::Zip::DOSTime.at(ctime)
40+
@flag, mt, at, ct = content.unpack('CVVV')
41+
mt && @mtime ||= ::Zip::DOSTime.at(mt)
42+
at && @atime ||= ::Zip::DOSTime.at(at)
43+
ct && @ctime ||= ::Zip::DOSTime.at(ct)
2544
end
2645

2746
def ==(other)

0 commit comments

Comments
 (0)