subversion/libsvn_wc/wc_db_pristine.c
/* Handle the moving of a pristine from SRC_WCROOT to DST_WCROOT. The existing
   pristine in SRC_WCROOT is described by CHECKSUM, MD5_CHECKSUM and SIZE */
Handle the moving of a pristine from SRC_WCROOT to DST_WCROOT. The existing
pristine in SRC_WCROOT is described by CHECKSUM, MD5_CHECKSUM and SIZE
Handle the moving of a pristine from SRC_WCROOT to DST_WCROOT . The existing pristine in SRC_WCROOT is described by CHECKSUM MD5_CHECKSUM and SIZE
static svn_error_t *
maybe_transfer_one_pristine(svn_wc__db_wcroot_t *src_wcroot,
                            svn_wc__db_wcroot_t *dst_wcroot,
                            const svn_checksum_t *checksum,
                            const svn_checksum_t *md5_checksum,
                            apr_int64_t size,
                            svn_cancel_func_t cancel_func,
                            void *cancel_baton,
                            apr_pool_t *scratch_pool)
{
  const char *pristine_abspath;
  svn_sqlite__stmt_t *stmt;
  svn_stream_t *src_stream;
  svn_stream_t *dst_stream;
  const char *tmp_abspath;
  const char *src_abspath;
  int affected_rows;
  svn_error_t *err;
  SVN_ERR(svn_sqlite__get_statement(&stmt, dst_wcroot->sdb,
                                    STMT_INSERT_OR_IGNORE_PRISTINE));
  SVN_ERR(svn_sqlite__bind_checksum(stmt, 1, checksum, scratch_pool));
  SVN_ERR(svn_sqlite__bind_checksum(stmt, 2, md5_checksum, scratch_pool));
  SVN_ERR(svn_sqlite__bind_int64(stmt, 3, size));
  SVN_ERR(svn_sqlite__update(&affected_rows, stmt));
  if (affected_rows == 0)
    return SVN_NO_ERROR;
  SVN_ERR(svn_stream_open_unique(&dst_stream, &tmp_abspath,
                                 pristine_get_tempdir(dst_wcroot,
                                                      scratch_pool,
                                                      scratch_pool),
                                 svn_io_file_del_on_pool_cleanup,
                                 scratch_pool, scratch_pool));
  SVN_ERR(get_pristine_fname(&src_abspath, src_wcroot->abspath, checksum,
                             scratch_pool, scratch_pool));
  SVN_ERR(svn_stream_open_readonly(&src_stream, src_abspath,
                                   scratch_pool, scratch_pool));
  SVN_ERR(svn_stream_copy3(src_stream, dst_stream,
                           cancel_func, cancel_baton,
                           scratch_pool));
  SVN_ERR(get_pristine_fname(&pristine_abspath, dst_wcroot->abspath, checksum,
                             scratch_pool, scratch_pool));
  err = svn_io_file_rename(tmp_abspath, pristine_abspath, scratch_pool);
  if (err && APR_STATUS_IS_ENOENT(err->apr_err))
    {
      svn_error_t *err2;
      err2 = svn_io_dir_make(svn_dirent_dirname(pristine_abspath,
                                                scratch_pool),
                             APR_OS_DEFAULT, scratch_pool);
      if (err2)
        return svn_error_trace(svn_error_compose_create(err, err2));
      else
        svn_error_clear(err);
      SVN_ERR(svn_io_file_rename(tmp_abspath, pristine_abspath, scratch_pool));
    }
  else
    SVN_ERR(err);
  return SVN_NO_ERROR;
}
static svn_error_t * maybe_transfer_one_pristine ( svn_wc__db_wcroot_t * src_wcroot , svn_wc__db_wcroot_t * dst_wcroot , const svn_checksum_t * checksum , const svn_checksum_t * md5_checksum , apr_int64_t size , svn_cancel_func_t cancel_func , void * cancel_baton , apr_pool_t * scratch_pool ) { const char * pristine_abspath ; svn_sqlite__stmt_t * stmt ; svn_stream_t * src_stream ; svn_stream_t * dst_stream ; const char * tmp_abspath ; const char * src_abspath ; int affected_rows ; svn_error_t * err ; SVN_ERR ( svn_sqlite__get_statement ( & stmt , dst_wcroot -> sdb , STMT_INSERT_OR_IGNORE_PRISTINE ) ) ; SVN_ERR ( svn_sqlite__bind_checksum ( stmt , 1 , checksum , scratch_pool ) ) ; SVN_ERR ( svn_sqlite__bind_checksum ( stmt , 2 , md5_checksum , scratch_pool ) ) ; SVN_ERR ( svn_sqlite__bind_int64 ( stmt , 3 , size ) ) ; SVN_ERR ( svn_sqlite__update ( & affected_rows , stmt ) ) ; if ( affected_rows == 0 ) return SVN_NO_ERROR ; SVN_ERR ( svn_stream_open_unique ( & dst_stream , & tmp_abspath , pristine_get_tempdir ( dst_wcroot , scratch_pool , scratch_pool ) , svn_io_file_del_on_pool_cleanup , scratch_pool , scratch_pool ) ) ; SVN_ERR ( get_pristine_fname ( & src_abspath , src_wcroot -> abspath , checksum , scratch_pool , scratch_pool ) ) ; SVN_ERR ( svn_stream_open_readonly ( & src_stream , src_abspath , scratch_pool , scratch_pool ) ) ; SVN_ERR ( svn_stream_copy3 ( src_stream , dst_stream , cancel_func , cancel_baton , scratch_pool ) ) ; SVN_ERR ( get_pristine_fname ( & pristine_abspath , dst_wcroot -> abspath , checksum , scratch_pool , scratch_pool ) ) ; err = svn_io_file_rename ( tmp_abspath , pristine_abspath , scratch_pool ) ; if ( err && APR_STATUS_IS_ENOENT ( err -> apr_err ) ) { svn_error_t * err2 ; err2 = svn_io_dir_make ( svn_dirent_dirname ( pristine_abspath , scratch_pool ) , APR_OS_DEFAULT , scratch_pool ) ; if ( err2 ) return svn_error_trace ( svn_error_compose_create ( err , err2 ) ) ; else svn_error_clear ( err ) ; SVN_ERR ( svn_io_file_rename ( tmp_abspath , pristine_abspath , scratch_pool ) ) ; } else SVN_ERR ( err ) ; return SVN_NO_ERROR ; }
Handle the moving of a pristine from SRC_WCROOT to DST_WCROOT.
Handle the moving of a pristine from SRC_WCROOT to DST_WCROOT .
/* ### Should we verify the SHA1 or MD5 here, or is that too expensive? */ /* Move the file to its target location.  (If it is already there, it is
   * an orphan file and it doesn't matter if we overwrite it.) */ /* Maybe the directory doesn't exist yet? */ /* Creating directory didn't work: Return all errors */ /* We could create a directory: retry install */