FreeBSD/contrib/subversion/subversion/libsvn_fs_fs/lock.c
/* Write to DIGEST_PATH a representation of CHILDREN (which may be
   empty, if the versioned path in FS represented by DIGEST_PATH has
   no children) and LOCK (which may be NULL if that versioned path is
   lock itself locked).  Set the permissions of DIGEST_PATH to those of
   PERMS_REFERENCE.  Use POOL for all allocations.
 */
Write to DIGEST_PATH a representation of CHILDREN (which may be
empty, if the versioned path in FS represented by DIGEST_PATH has
no children) and LOCK (which may be NULL if that versioned path is
lock itself locked).  Set the permissions of DIGEST_PATH to those of
PERMS_REFERENCE.  Use POOL for all allocations.
Write to DIGEST_PATH a representation of CHILDREN ( which may be empty if the versioned path in FS represented by DIGEST_PATH has no children ) and LOCK ( which may be NULL if that versioned path is lock itself locked ) . Set the permissions of DIGEST_PATH to those of PERMS_REFERENCE . Use POOL for all allocations .
static svn_error_t *
write_digest_file(apr_hash_t *children,
                  svn_lock_t *lock,
                  const char *fs_path,
                  const char *digest_path,
                  const char *perms_reference,
                  apr_pool_t *pool)
{
  svn_error_t *err = SVN_NO_ERROR;
  svn_stream_t *stream;
  apr_hash_index_t *hi;
  apr_hash_t *hash = apr_hash_make(pool);
  const char *tmp_path;
  SVN_ERR(svn_fs_fs__ensure_dir_exists(svn_dirent_join(fs_path, PATH_LOCKS_DIR,
                                                       pool), fs_path, pool));
  SVN_ERR(svn_fs_fs__ensure_dir_exists(svn_dirent_dirname(digest_path, pool),
                                       fs_path, pool));
  if (lock)
    {
      const char *creation_date = NULL, *expiration_date = NULL;
      if (lock->creation_date)
        creation_date = svn_time_to_cstring(lock->creation_date, pool);
      if (lock->expiration_date)
        expiration_date = svn_time_to_cstring(lock->expiration_date, pool);
      hash_store(hash, PATH_KEY, sizeof(PATH_KEY)-1,
                 lock->path, APR_HASH_KEY_STRING, pool);
      hash_store(hash, TOKEN_KEY, sizeof(TOKEN_KEY)-1,
                 lock->token, APR_HASH_KEY_STRING, pool);
      hash_store(hash, OWNER_KEY, sizeof(OWNER_KEY)-1,
                 lock->owner, APR_HASH_KEY_STRING, pool);
      hash_store(hash, COMMENT_KEY, sizeof(COMMENT_KEY)-1,
                 lock->comment, APR_HASH_KEY_STRING, pool);
      hash_store(hash, IS_DAV_COMMENT_KEY, sizeof(IS_DAV_COMMENT_KEY)-1,
                 lock->is_dav_comment ? "1" : "0", 1, pool);
      hash_store(hash, CREATION_DATE_KEY, sizeof(CREATION_DATE_KEY)-1,
                 creation_date, APR_HASH_KEY_STRING, pool);
      hash_store(hash, EXPIRATION_DATE_KEY, sizeof(EXPIRATION_DATE_KEY)-1,
                 expiration_date, APR_HASH_KEY_STRING, pool);
    }
  if (apr_hash_count(children))
    {
      svn_stringbuf_t *children_list = svn_stringbuf_create_empty(pool);
      for (hi = apr_hash_first(pool, children); hi; hi = apr_hash_next(hi))
        {
          svn_stringbuf_appendbytes(children_list,
                                    apr_hash_this_key(hi),
                                    apr_hash_this_key_len(hi));
          svn_stringbuf_appendbyte(children_list, '\n');
        }
      hash_store(hash, CHILDREN_KEY, sizeof(CHILDREN_KEY)-1,
                 children_list->data, children_list->len, pool);
    }
  SVN_ERR(svn_stream_open_unique(&stream, &tmp_path,
                                 svn_dirent_dirname(digest_path, pool),
                                 svn_io_file_del_none, pool, pool));
  if ((err = svn_hash_write2(hash, stream, SVN_HASH_TERMINATOR, pool)))
    {
      svn_error_clear(svn_stream_close(stream));
      return svn_error_createf(err->apr_err,
                               err,
                               _("Cannot write lock/entries hashfile '%s'"),
                               svn_dirent_local_style(tmp_path, pool));
    }
  SVN_ERR(svn_stream_close(stream));
  SVN_ERR(svn_io_file_rename(tmp_path, digest_path, pool));
  SVN_ERR(svn_io_copy_perms(perms_reference, digest_path, pool));
  return SVN_NO_ERROR;
}
static svn_error_t * write_digest_file ( apr_hash_t * children , svn_lock_t * lock , const char * fs_path , const char * digest_path , const char * perms_reference , apr_pool_t * pool ) { svn_error_t * err = SVN_NO_ERROR ; svn_stream_t * stream ; apr_hash_index_t * hi ; apr_hash_t * hash = apr_hash_make ( pool ) ; const char * tmp_path ; SVN_ERR ( svn_fs_fs__ensure_dir_exists ( svn_dirent_join ( fs_path , PATH_LOCKS_DIR , pool ) , fs_path , pool ) ) ; SVN_ERR ( svn_fs_fs__ensure_dir_exists ( svn_dirent_dirname ( digest_path , pool ) , fs_path , pool ) ) ; if ( lock ) { const char * creation_date = NULL , * expiration_date = NULL ; if ( lock -> creation_date ) creation_date = svn_time_to_cstring ( lock -> creation_date , pool ) ; if ( lock -> expiration_date ) expiration_date = svn_time_to_cstring ( lock -> expiration_date , pool ) ; hash_store ( hash , PATH_KEY , sizeof ( PATH_KEY ) - 1 , lock -> path , APR_HASH_KEY_STRING , pool ) ; hash_store ( hash , TOKEN_KEY , sizeof ( TOKEN_KEY ) - 1 , lock -> token , APR_HASH_KEY_STRING , pool ) ; hash_store ( hash , OWNER_KEY , sizeof ( OWNER_KEY ) - 1 , lock -> owner , APR_HASH_KEY_STRING , pool ) ; hash_store ( hash , COMMENT_KEY , sizeof ( COMMENT_KEY ) - 1 , lock -> comment , APR_HASH_KEY_STRING , pool ) ; hash_store ( hash , IS_DAV_COMMENT_KEY , sizeof ( IS_DAV_COMMENT_KEY ) - 1 , lock -> is_dav_comment ? " " : " " , 1 , pool ) ; hash_store ( hash , CREATION_DATE_KEY , sizeof ( CREATION_DATE_KEY ) - 1 , creation_date , APR_HASH_KEY_STRING , pool ) ; hash_store ( hash , EXPIRATION_DATE_KEY , sizeof ( EXPIRATION_DATE_KEY ) - 1 , expiration_date , APR_HASH_KEY_STRING , pool ) ; } if ( apr_hash_count ( children ) ) { svn_stringbuf_t * children_list = svn_stringbuf_create_empty ( pool ) ; for ( hi = apr_hash_first ( pool , children ) ; hi ; hi = apr_hash_next ( hi ) ) { svn_stringbuf_appendbytes ( children_list , apr_hash_this_key ( hi ) , apr_hash_this_key_len ( hi ) ) ; svn_stringbuf_appendbyte ( children_list , ' \n ' ) ; } hash_store ( hash , CHILDREN_KEY , sizeof ( CHILDREN_KEY ) - 1 , children_list -> data , children_list -> len , pool ) ; } SVN_ERR ( svn_stream_open_unique ( & stream , & tmp_path , svn_dirent_dirname ( digest_path , pool ) , svn_io_file_del_none , pool , pool ) ) ; if ( ( err = svn_hash_write2 ( hash , stream , SVN_HASH_TERMINATOR , pool ) ) ) { svn_error_clear ( svn_stream_close ( stream ) ) ; return svn_error_createf ( err -> apr_err , err , _ ( " " ) , svn_dirent_local_style ( tmp_path , pool ) ) ; } SVN_ERR ( svn_stream_close ( stream ) ) ; SVN_ERR ( svn_io_file_rename ( tmp_path , digest_path , pool ) ) ; SVN_ERR ( svn_io_copy_perms ( perms_reference , digest_path , pool ) ) ; return SVN_NO_ERROR ; }
Write to DIGEST_PATH a representation of CHILDREN (which may be
empty, if the versioned path in FS represented by DIGEST_PATH has
no children) and LOCK (which may be NULL if that versioned path is
lock itself locked).
Write to DIGEST_PATH a representation of CHILDREN ( which may be empty if the versioned path in FS represented by DIGEST_PATH has no children ) and LOCK ( which may be NULL if that versioned path is lock itself locked ) .