comparison mercurial/archival.py @ 17629:331d611813ec

Merge with crew-stable
author Bryan O'Sullivan <bryano@fb.com>
date Wed, 19 Sep 2012 09:38:51 -0700
parents 72fa4ef2245f 133d13e44544
children 49ad7030ecc4
comparison
equal deleted inserted replaced
17627:84f12b832ee8 17629:331d611813ec
10 import match as matchmod 10 import match as matchmod
11 import cmdutil 11 import cmdutil
12 import scmutil, util, encoding 12 import scmutil, util, encoding
13 import cStringIO, os, tarfile, time, zipfile 13 import cStringIO, os, tarfile, time, zipfile
14 import zlib, gzip 14 import zlib, gzip
15 import struct
15 16
16 # from unzip source code: 17 # from unzip source code:
17 _UNX_IFREG = 0x8000 18 _UNX_IFREG = 0x8000
18 _UNX_IFLNK = 0xa000 19 _UNX_IFLNK = 0xa000
19 20
167 # to store files with a date before 1980. 168 # to store files with a date before 1980.
168 epoch = 315532800 # calendar.timegm((1980, 1, 1, 0, 0, 0, 1, 1, 0)) 169 epoch = 315532800 # calendar.timegm((1980, 1, 1, 0, 0, 0, 1, 1, 0))
169 if mtime < epoch: 170 if mtime < epoch:
170 mtime = epoch 171 mtime = epoch
171 172
173 self.mtime = mtime
172 self.date_time = time.gmtime(mtime)[:6] 174 self.date_time = time.gmtime(mtime)[:6]
173 175
174 def addfile(self, name, mode, islink, data): 176 def addfile(self, name, mode, islink, data):
175 i = zipfile.ZipInfo(name, self.date_time) 177 i = zipfile.ZipInfo(name, self.date_time)
176 i.compress_type = self.z.compression 178 i.compress_type = self.z.compression
180 ftype = _UNX_IFREG 182 ftype = _UNX_IFREG
181 if islink: 183 if islink:
182 mode = 0777 184 mode = 0777
183 ftype = _UNX_IFLNK 185 ftype = _UNX_IFLNK
184 i.external_attr = (mode | ftype) << 16L 186 i.external_attr = (mode | ftype) << 16L
187 # add "extended-timestamp" extra block, because zip archives
188 # without this will be extracted with unexpected timestamp,
189 # if TZ is not configured as GMT
190 i.extra += struct.pack('<hhBl',
191 0x5455, # block type: "extended-timestamp"
192 1 + 4, # size of this block
193 1, # "modification time is present"
194 self.mtime) # time of last modification (UTC)
185 self.z.writestr(i, data) 195 self.z.writestr(i, data)
186 196
187 def done(self): 197 def done(self):
188 self.z.close() 198 self.z.close()
189 199