FreeBSD/contrib/subversion/subversion/libsvn_wc/wc_db_pristine.c
/* Install the pristine text described by BATON into the pristine store of
 * SDB.  If it is already stored then just delete the new file
 * BATON->tempfile_abspath.
 *
 * This function expects to be executed inside a SQLite txn that has already
 * acquired a 'RESERVED' lock.
 *
 * Implements 'notes/wc-ng/pristine-store' section A-3(a).
 */
Install the pristine text described by BATON into the pristine store of
SDB.  If it is already stored then just delete the new file
BATON->tempfile_abspath.

This function expects to be executed inside a SQLite txn that has already
acquired a 'RESERVED' lock.


Install the pristine text described by BATON into the pristine store of SDB . If it is already stored then just delete the new file BATON - > tempfile_abspath . This function expects to be executed inside a SQLite txn that has already acquired a ' RESERVED ' lock .
static svn_error_t *
pristine_install_txn(svn_sqlite__db_t *sdb,
                     svn_stream_t *install_stream,
                     const char *pristine_abspath,
                     const svn_checksum_t *sha1_checksum,
                     const svn_checksum_t *md5_checksum,
                     apr_pool_t *scratch_pool)
{
  svn_sqlite__stmt_t *stmt;
  svn_boolean_t have_row;
  SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, STMT_SELECT_PRISTINE));
  SVN_ERR(svn_sqlite__bind_checksum(stmt, 1, sha1_checksum, scratch_pool));
  SVN_ERR(svn_sqlite__step(&have_row, stmt));
  SVN_ERR(svn_sqlite__reset(stmt));
  if (have_row)
    {
#ifdef SVN_DEBUG
      {
        apr_finfo_t finfo1, finfo2;
        SVN_ERR(svn_stream__install_get_info(&finfo1, install_stream, APR_FINFO_SIZE,
                                             scratch_pool));
        SVN_ERR(svn_io_stat(&finfo2, pristine_abspath, APR_FINFO_SIZE,
                            scratch_pool));
        if (finfo1.size != finfo2.size)
          {
            return svn_error_createf(
              SVN_ERR_WC_CORRUPT_TEXT_BASE, NULL,
              _("New pristine text '%s' has different size: %ld versus %ld"),
              svn_checksum_to_cstring_display(sha1_checksum, scratch_pool),
              (long int)finfo1.size, (long int)finfo2.size);
          }
      }
#endif
      SVN_ERR(svn_stream__install_delete(install_stream, scratch_pool));
      return SVN_NO_ERROR;
    }
  {
    apr_finfo_t finfo;
    SVN_ERR(svn_stream__install_get_info(&finfo, install_stream, APR_FINFO_SIZE,
                                         scratch_pool));
    SVN_ERR(svn_stream__install_stream(install_stream, pristine_abspath,
                                        TRUE, scratch_pool));
    SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
                                      STMT_INSERT_PRISTINE));
    SVN_ERR(svn_sqlite__bind_checksum(stmt, 1, sha1_checksum, scratch_pool));
    SVN_ERR(svn_sqlite__bind_checksum(stmt, 2, md5_checksum, scratch_pool));
    SVN_ERR(svn_sqlite__bind_int64(stmt, 3, finfo.size));
    SVN_ERR(svn_sqlite__insert(NULL, stmt));
    SVN_ERR(svn_io_set_file_read_only(pristine_abspath, FALSE, scratch_pool));
  }
  return SVN_NO_ERROR;
}
static svn_error_t * pristine_install_txn ( svn_sqlite__db_t * sdb , svn_stream_t * install_stream , const char * pristine_abspath , const svn_checksum_t * sha1_checksum , const svn_checksum_t * md5_checksum , apr_pool_t * scratch_pool ) { svn_sqlite__stmt_t * stmt ; svn_boolean_t have_row ; SVN_ERR ( svn_sqlite__get_statement ( & stmt , sdb , STMT_SELECT_PRISTINE ) ) ; SVN_ERR ( svn_sqlite__bind_checksum ( stmt , 1 , sha1_checksum , scratch_pool ) ) ; SVN_ERR ( svn_sqlite__step ( & have_row , stmt ) ) ; SVN_ERR ( svn_sqlite__reset ( stmt ) ) ; if ( have_row ) { #ifdef SVN_DEBUG { apr_finfo_t finfo1 , finfo2 ; SVN_ERR ( svn_stream__install_get_info ( & finfo1 , install_stream , APR_FINFO_SIZE , scratch_pool ) ) ; SVN_ERR ( svn_io_stat ( & finfo2 , pristine_abspath , APR_FINFO_SIZE , scratch_pool ) ) ; if ( finfo1 . size != finfo2 . size ) { return svn_error_createf ( SVN_ERR_WC_CORRUPT_TEXT_BASE , NULL , _ ( " " ) , svn_checksum_to_cstring_display ( sha1_checksum , scratch_pool ) , ( long int ) finfo1 . size , ( long int ) finfo2 . size ) ; } } #endif SVN_ERR ( svn_stream__install_delete ( install_stream , scratch_pool ) ) ; return SVN_NO_ERROR ; } { apr_finfo_t finfo ; SVN_ERR ( svn_stream__install_get_info ( & finfo , install_stream , APR_FINFO_SIZE , scratch_pool ) ) ; SVN_ERR ( svn_stream__install_stream ( install_stream , pristine_abspath , TRUE , scratch_pool ) ) ; SVN_ERR ( svn_sqlite__get_statement ( & stmt , sdb , STMT_INSERT_PRISTINE ) ) ; SVN_ERR ( svn_sqlite__bind_checksum ( stmt , 1 , sha1_checksum , scratch_pool ) ) ; SVN_ERR ( svn_sqlite__bind_checksum ( stmt , 2 , md5_checksum , scratch_pool ) ) ; SVN_ERR ( svn_sqlite__bind_int64 ( stmt , 3 , finfo . size ) ) ; SVN_ERR ( svn_sqlite__insert ( NULL , stmt ) ) ; SVN_ERR ( svn_io_set_file_read_only ( pristine_abspath , FALSE , scratch_pool ) ) ; } return SVN_NO_ERROR ; }
Install the pristine text described by BATON into the pristine store of
 SDB.
Install the pristine text described by BATON into the pristine store of SDB .
/* The path to the source file that is to be moved into place. */ /* The target path for the file (within the pristine store). */ /* The pristine text's SHA-1 checksum. */ /* The pristine text's MD-5 checksum. */ /* If this pristine text is already present in the store, just keep it:
   * delete the new one and return. */ /* Consistency checks.  Verify both files exist and match.
       * ### We could check much more. */ /* Remove the temp file: it's already there */ /* 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.) */