Exemple #1
0
    def _GetFileViaZsync(self, remote, local_path, current_file):
        """Retrieve a file using zsync.

    Args:
      remote: Remote url to fetch
      local_path: local filename to use.
      current_file: path to the current cache file.
    Returns:
      local path
    """
        self.log.debug('ZSync URL: %s', remote)
        zs = zsync.Zsync(conn=self.conn,
                         retry_max=self.conf['retry_max'],
                         retry_delay=self.conf['retry_delay'])
        try:
            zs.Begin(remote + self.conf['zsync_suffix'])
            if current_file and os.path.exists(current_file):
                zs.SubmitSource(current_file)
            zs.Fetch(local_path)
        except zsync.error.Error, e:
            raise error.InvalidMap('Unable to retrieve zsync file: %s' % e)
Exemple #2
0
  def _FullUpdateFromFile(self, cache, source_map, force_write=False):
    """Write a new map into the provided cache (overwrites).

    Args:
      cache: A nss_cache.caches.Cache object.
      source_map: The map whose contents we're replacing the cache with, that is
        used for verification.
      force_write: A boolean flag forcing empty map updates when False,
        defaults to False.

    Returns:
      0 if succesful, non-zero indicating number of failures otherwise.

    Raises:
      EmptyMap: Update is an empty map, not raised if force_write=True.
      InvalidMap:
    """
    return_val = 0

    for entry in source_map:
      if not entry.Verify():
        raise error.InvalidMap('Map is not valid. Aborting')

    if len(source_map) is 0 and not force_write:
      raise error.EmptyMap('Source map empty during full update, aborting. '
                           'Use --force-write to override.')

    return_val += cache.WriteMap(map_data=source_map)

    # We did an update, write our timestamps unless there is an error.
    if return_val is 0:
      mtime = os.stat(cache.GetCacheFilename()).st_mtime
      gmtime = time.gmtime(mtime)
      self.log.debug('Cache filename %s has mtime %d, gmtime %r',
                     cache.GetCacheFilename(), mtime, gmtime)
      self.WriteModifyTimestamp(gmtime)
      self.WriteUpdateTimestamp()

    return return_val
Exemple #3
0
        try:
            zs.Begin(remote + self.conf['zsync_suffix'])
            if current_file and os.path.exists(current_file):
                zs.SubmitSource(current_file)
            zs.Fetch(local_path)
        except zsync.error.Error, e:
            raise error.InvalidMap('Unable to retrieve zsync file: %s' % e)

        if not os.path.exists(local_path):
            raise error.EmptyMap()

        if self.conf['gpg']:
            remote_sig = remote + self.conf['gpg_suffix']
            if not self._GPGVerify(local_path, remote_sig):
                self.log.warning('Invalid GPG signature for %s', remote)
                raise error.InvalidMap('Unable to verify map')

        return local_path

    def GetPasswdFile(self, dst_file, current_file):
        """Retrieve passwd file via zsync.

    Args:
      dst_file: Destination file (temp)
      current_file: path to the current cache file.
    Returns:
      file object
    """
        tmp = self._GetFile(self.conf['passwd_url'], dst_file, current_file)
        return open(tmp)