def extract_file(self, myzip, zipinfo): fname = zipinfo.filename ufname = util.force_decode(fname) path = os.path.join(self.dstdir, ufname) if stat.S_ISDIR(zipinfo.external_attr >> 16): dirpath = os.path.join(self.dstdir, ufname) if not os.path.exists(dirpath): os.makedirs(dirpath) self.dirlist.append(fname) else: dirpath = os.path.join(self.dstdir, util.unix_dirname(ufname)) if not os.path.exists(dirpath): os.makedirs(dirpath) source = myzip.open(fname) try: target = open(path, "wb") self.update("Inflating: {0}".format(ufname)) shutil.copyfileobj(source, target) self.notify("Inflated: {0}".format(ufname)) source.close() target.close() self.copy_external_attr(myzip, fname) except IOError as e: if e[0] == errno.EISDIR: self.dirlist.append(fname)
def copy_external_attr(self, myzip, path): try: info = myzip.getinfo(path) except Exception as e: return message.exception(e) perm = info.external_attr >> 16 date = list(info.date_time) + [-1, -1, -1] path = util.force_decode(path) abspath = os.path.join(self.dstdir, path) try: if perm: os.chmod(abspath, perm) atime = mtime = time.mktime(date) os.utime(abspath, (atime, mtime)) except Exception as e: message.exception(e)