def _add_manifest_entry()

in pkg/private/zip/build_zip.py [0:0]


def _add_manifest_entry(options, zip_file, entry, default_mode, ts):
  """Add an entry to the zip file.

  Args:
    options: parsed options
    zip_file: ZipFile to write to
    entry: manifest entry
    default_mode: (int) file mode to use if not specified in the entry.
    ts: (int) time stamp to add to files
  """

  entry_type, dest, src, mode, user, group = entry

  # Use the pkg_tar mode/owner remaping as a fallback
  non_abs_path = dest.strip('/')
  dst_path = _combine_paths(options.directory, non_abs_path)
  if entry_type == manifest.ENTRY_IS_DIR and not dst_path.endswith('/'):
    dst_path += '/'
  entry_info = zipfile.ZipInfo(filename=dst_path, date_time=ts)
  # See http://www.pkware.com/documents/casestudies/APPNOTE.TXT
  # denotes UTF-8 encoded file name.
  entry_info.flag_bits |= 0x800
  if mode:
    f_mode = int(mode, 8)
  else:
    f_mode = default_mode

  # See: https://trac.edgewall.org/attachment/ticket/8919/ZipDownload.patch
  # external_attr is 4 bytes in size. The high order two bytes represent UNIX
  # permission and file type bits, while the low order two contain MS-DOS FAT file
  # attributes.
  entry_info.external_attr = f_mode << 16
  if entry_type == manifest.ENTRY_IS_FILE:
    entry_info.compress_type = zipfile.ZIP_DEFLATED
    with open(src, 'rb') as src:
      zip_file.writestr(entry_info, src.read())
  elif entry_type == manifest.ENTRY_IS_DIR:
    entry_info.compress_type = zipfile.ZIP_STORED
    # Set directory bits
    entry_info.external_attr |= (UNIX_DIR_BIT << 16) | MSDOS_DIR_BIT
    zip_file.writestr(entry_info, '')
  elif entry_type == manifest.ENTRY_IS_LINK:
    entry_info.compress_type = zipfile.ZIP_STORED
    # Set directory bits
    entry_info.external_attr |= (UNIX_SYMLINK_BIT << 16)
    zip_file.writestr(entry_info, src)