-
Notifications
You must be signed in to change notification settings - Fork 312
/
old_unix.rb
46 lines (38 loc) · 1.02 KB
/
old_unix.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Zip
# Olf Info-ZIP Extra for UNIX uid/gid and file timestampes
class ExtraField::OldUnix < ExtraField::Generic
HEADER_ID = 'UX'
register_map
def initialize(binstr = nil)
@uid = 0
@gid = 0
@atime = nil
@mtime = nil
binstr && merge(binstr)
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
atime, mtime, uid, gid = content.unpack('VVvv')
@uid ||= uid
@gid ||= gid
@atime ||= atime
@mtime ||= mtime # rubocop:disable Naming/MemoizedInstanceVariableName
end
def ==(other)
@uid == other.uid &&
@gid == other.gid &&
@atime == other.atime &&
@mtime == other.mtime
end
def pack_for_local
[@atime, @mtime, @uid, @gid].pack('VVvv')
end
def pack_for_c_dir
[@atime, @mtime].pack('VV')
end
end
end