FreeBSD/contrib/subversion/subversion/libsvn_fs_x/cached_data.c
/* BATON is of type `rep_read_baton_t'; read the next *LEN bytes of the
   representation and store them in *BUF.  Sum as we read and verify
   the MD5 sum at the end. */
BATON is of type `rep_read_baton_t'; read the next *LEN bytes of the
representation and store them in *BUF.  Sum as we read and verify
the MD5 sum at the end.
BATON is of type ` rep_read_baton_t ' ; read the next * LEN bytes of the representation and store them in * BUF . Sum as we read and verify the MD5 sum at the end .
static svn_error_t *
rep_read_contents(void *baton,
                  char *buf,
                  apr_size_t *len)
{
  rep_read_baton_t *rb = baton;
  if (rb->fulltext_cache)
    {
      svn_boolean_t cached;
      SVN_ERR(get_contents_from_fulltext(&cached, rb, buf, len));
      if (cached)
        return SVN_NO_ERROR;
      rb->fulltext_cache = NULL;
    }
  if (!rb->rs_list)
    {
      SVN_ERR(build_rep_list(&rb->rs_list, &rb->base_window,
                             &rb->src_state, rb->fs, &rb->rep,
                             rb->filehandle_pool, rb->scratch_pool));
      SVN_ERR(skip_contents(rb, rb->fulltext_delivered));
    }
  SVN_ERR(get_contents_from_windows(rb, buf, len));
  if (rb->current_fulltext)
    svn_stringbuf_appendbytes(rb->current_fulltext, buf, *len);
  if (!rb->checksum_finalized)
    {
      SVN_ERR(svn_checksum_update(rb->md5_checksum_ctx, buf, *len));
      rb->off += *len;
      if (rb->off == rb->len)
        {
          svn_checksum_t *md5_checksum;
          svn_checksum_t expected;
          expected.kind = svn_checksum_md5;
          expected.digest = rb->md5_digest;
          rb->checksum_finalized = TRUE;
          SVN_ERR(svn_checksum_final(&md5_checksum, rb->md5_checksum_ctx,
                                     rb->scratch_pool));
          if (!svn_checksum_match(md5_checksum, &expected))
            return svn_error_create(SVN_ERR_FS_CORRUPT,
                    svn_checksum_mismatch_err(&expected, md5_checksum,
                        rb->scratch_pool,
                        _("Checksum mismatch while reading representation")),
                    NULL);
        }
    }
  if (rb->off == rb->len && rb->current_fulltext)
    {
      svn_fs_x__data_t *ffd = rb->fs->fsap_data;
      SVN_ERR(svn_cache__set(ffd->fulltext_cache, &rb->fulltext_cache_key,
                             rb->current_fulltext, rb->scratch_pool));
      rb->current_fulltext = NULL;
    }
  return SVN_NO_ERROR;
}
static svn_error_t * rep_read_contents ( void * baton , char * buf , apr_size_t * len ) { rep_read_baton_t * rb = baton ; if ( rb -> fulltext_cache ) { svn_boolean_t cached ; SVN_ERR ( get_contents_from_fulltext ( & cached , rb , buf , len ) ) ; if ( cached ) return SVN_NO_ERROR ; rb -> fulltext_cache = NULL ; } if ( ! rb -> rs_list ) { SVN_ERR ( build_rep_list ( & rb -> rs_list , & rb -> base_window , & rb -> src_state , rb -> fs , & rb -> rep , rb -> filehandle_pool , rb -> scratch_pool ) ) ; SVN_ERR ( skip_contents ( rb , rb -> fulltext_delivered ) ) ; } SVN_ERR ( get_contents_from_windows ( rb , buf , len ) ) ; if ( rb -> current_fulltext ) svn_stringbuf_appendbytes ( rb -> current_fulltext , buf , * len ) ; if ( ! rb -> checksum_finalized ) { SVN_ERR ( svn_checksum_update ( rb -> md5_checksum_ctx , buf , * len ) ) ; rb -> off += * len ; if ( rb -> off == rb -> len ) { svn_checksum_t * md5_checksum ; svn_checksum_t expected ; expected . kind = svn_checksum_md5 ; expected . digest = rb -> md5_digest ; rb -> checksum_finalized = TRUE ; SVN_ERR ( svn_checksum_final ( & md5_checksum , rb -> md5_checksum_ctx , rb -> scratch_pool ) ) ; if ( ! svn_checksum_match ( md5_checksum , & expected ) ) return svn_error_create ( SVN_ERR_FS_CORRUPT , svn_checksum_mismatch_err ( & expected , md5_checksum , rb -> scratch_pool , _ ( " " ) ) , NULL ) ; } } if ( rb -> off == rb -> len && rb -> current_fulltext ) { svn_fs_x__data_t * ffd = rb -> fs -> fsap_data ; SVN_ERR ( svn_cache__set ( ffd -> fulltext_cache , & rb -> fulltext_cache_key , rb -> current_fulltext , rb -> scratch_pool ) ) ; rb -> current_fulltext = NULL ; } return SVN_NO_ERROR ; }
BATON is of type `rep_read_baton_t'; read the next *LEN bytes of the
representation and store them in *BUF.
BATON is of type ` rep_read_baton_t ' ; read the next * LEN bytes of the representation and store them in * BUF .
/* Get data from the fulltext cache for as long as we can. */ /* Cache miss.  From now on, we will never read from the fulltext
       * cache for this representation anymore. */ /* No fulltext cache to help us.  We must read from the window stream. */ /* Window stream not initialized, yet.  Do it now. */ /* In case we did read from the fulltext cache before, make the
       * window stream catch up.  Also, initialize the fulltext buffer
       * if we want to cache the fulltext at the end. */ /* Get the next block of data. */ /* Perform checksumming.  We want to check the checksum as soon as
     the last byte of data is read, in case the caller never performs
     a short read, but we don't want to finalize the MD5 context
     twice. */