FreeBSD/contrib/subversion/subversion/libsvn_ra_serf/update.c
/* Stream write function for body creation */
Stream write function for body creation
Stream write function for body creation
static svn_error_t *
body_write_fn(void *baton,
              const char *data,
              apr_size_t *len)
{
  body_create_baton_t *bcb = baton;
  if (!bcb->scratch_pool)
    bcb->scratch_pool = svn_pool_create(bcb->result_pool);
  if (bcb->file)
    {
      SVN_ERR(svn_io_file_write_full(bcb->file, data, *len, NULL,
                                     bcb->scratch_pool));
      svn_pool_clear(bcb->scratch_pool);
      bcb->total_bytes += *len;
    }
  else if (*len + bcb->total_bytes > MAX_BODY_IN_RAM)
    {
      SVN_ERR(svn_io_open_unique_file3(&bcb->file, NULL, NULL,
                                       svn_io_file_del_on_pool_cleanup,
                                       bcb->result_pool, bcb->scratch_pool));
      if (bcb->total_bytes)
        {
          const char *all = body_allocate_all(bcb, bcb->scratch_pool);
          SVN_ERR(svn_io_file_write_full(bcb->file, all, bcb->total_bytes,
                                         NULL, bcb->scratch_pool));
        }
      SVN_ERR(svn_io_file_write_full(bcb->file, data, *len, NULL,
                                     bcb->scratch_pool));
      bcb->total_bytes += *len;
    }
  else
    {
      if (!bcb->alloc)
        bcb->alloc = serf_bucket_allocator_create(bcb->scratch_pool,
                                                  serf_free_no_error, NULL);
      if (!bcb->collect_bucket)
        bcb->collect_bucket = serf_bucket_aggregate_create(bcb->alloc);
      serf_bucket_aggregate_append(bcb->collect_bucket,
                                   serf_bucket_simple_copy_create(data, *len,
                                                                  bcb->alloc));
      bcb->total_bytes += *len;
    }
  return SVN_NO_ERROR;
}
static svn_error_t * body_write_fn ( void * baton , const char * data , apr_size_t * len ) { body_create_baton_t * bcb = baton ; if ( ! bcb -> scratch_pool ) bcb -> scratch_pool = svn_pool_create ( bcb -> result_pool ) ; if ( bcb -> file ) { SVN_ERR ( svn_io_file_write_full ( bcb -> file , data , * len , NULL , bcb -> scratch_pool ) ) ; svn_pool_clear ( bcb -> scratch_pool ) ; bcb -> total_bytes += * len ; } else if ( * len + bcb -> total_bytes > MAX_BODY_IN_RAM ) { SVN_ERR ( svn_io_open_unique_file3 ( & bcb -> file , NULL , NULL , svn_io_file_del_on_pool_cleanup , bcb -> result_pool , bcb -> scratch_pool ) ) ; if ( bcb -> total_bytes ) { const char * all = body_allocate_all ( bcb , bcb -> scratch_pool ) ; SVN_ERR ( svn_io_file_write_full ( bcb -> file , all , bcb -> total_bytes , NULL , bcb -> scratch_pool ) ) ; } SVN_ERR ( svn_io_file_write_full ( bcb -> file , data , * len , NULL , bcb -> scratch_pool ) ) ; bcb -> total_bytes += * len ; } else { if ( ! bcb -> alloc ) bcb -> alloc = serf_bucket_allocator_create ( bcb -> scratch_pool , serf_free_no_error , NULL ) ; if ( ! bcb -> collect_bucket ) bcb -> collect_bucket = serf_bucket_aggregate_create ( bcb -> alloc ) ; serf_bucket_aggregate_append ( bcb -> collect_bucket , serf_bucket_simple_copy_create ( data , * len , bcb -> alloc ) ) ; bcb -> total_bytes += * len ; } return SVN_NO_ERROR ; }
Stream write function for body creation
Stream write function for body creation