/* * mw_svn_get() * * Return the contents of the head of the file at subversion location * <url>. On failure return NULL. */ char * mw_svn_get(const char *url, void *baton, apr_pool_t *pool) { svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx; svn_stream_t *out; apr_pool_t *subpool = svn_pool_create(pool); svn_stringbuf_t *string; svn_error_t *err = NULL; svn_opt_revision_t rev; char *res; string = svn_stringbuf_create("", pool); out = svn_stream_from_stringbuf(string, pool); /* For now, we always want the HEAD revision, but in future we * may want to support specifying a revision here.*/ rev.kind = svn_opt_revision_head; svn_pool_clear(subpool); err = svn_client_cat(out, url, &rev, ctx, subpool); if (err != NULL) { svn_pool_destroy(subpool); svn_stream_close(out); return (NULL); } res = xstrdup(string->data); svn_pool_destroy(subpool); svn_stream_close(out); return (res); }
/* Dumps the contents of a file to stdout */ static svn_error_t *delta_cat_file(apr_pool_t *pool, const char *path) { svn_error_t *err; apr_status_t status; apr_file_t *in_file = NULL; svn_stream_t *in, *out; status = apr_file_open(&in_file, path, APR_READ, 0600, pool); if (status) { apr_pool_t *epool = svn_pool_create(NULL); char *errbuf = apr_palloc(epool, ERRBUFFER_SIZE); return svn_error_create(status, NULL, apr_strerror(status, errbuf, ERRBUFFER_SIZE)); } in = svn_stream_from_aprfile2(in_file, FALSE, pool); if ((err = svn_stream_for_stdout(&out, pool))) { svn_stream_close(in); return err; } /* Write contents */ if ((err = svn_stream_copy(in, out, pool))) { svn_stream_close(in); return err; } err = svn_stream_close(in); return SVN_NO_ERROR; }
static svn_error_t * fetch_base_func(const char **filename, void *baton, const char *path, svn_revnum_t base_revision, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { struct edit_baton *eb = baton; svn_stream_t *fstream; svn_error_t *err; SVN_ERR(svn_stream_open_unique(&fstream, filename, NULL, svn_io_file_del_on_pool_cleanup, result_pool, scratch_pool)); err = svn_ra_get_file(eb->ra_session, path, eb->revision, fstream, NULL, NULL, scratch_pool); if (err && err->apr_err == SVN_ERR_FS_NOT_FOUND) { svn_error_clear(err); SVN_ERR(svn_stream_close(fstream)); *filename = NULL; return SVN_NO_ERROR; } else if (err) return svn_error_trace(err); SVN_ERR(svn_stream_close(fstream)); return SVN_NO_ERROR; }
static svn_error_t * close_handler_tee(void *baton) { struct baton_tee *bt = baton; SVN_ERR(svn_stream_close(bt->out1)); SVN_ERR(svn_stream_close(bt->out2)); return SVN_NO_ERROR; }
/* Print dumpstream-formatted information about REVISION. * Implements the `svn_ra_replay_revstart_callback_t' interface. */ static svn_error_t * replay_revstart(svn_revnum_t revision, void *replay_baton, const svn_delta_editor_t **editor, void **edit_baton, apr_hash_t *rev_props, apr_pool_t *pool) { struct replay_baton *rb = replay_baton; apr_hash_t *normal_props; svn_stringbuf_t *propstring; svn_stream_t *stdout_stream; svn_stream_t *revprop_stream; SVN_ERR(svn_stream_for_stdout(&stdout_stream, pool)); /* Revision-number: 19 */ SVN_ERR(svn_stream_printf(stdout_stream, pool, SVN_REPOS_DUMPFILE_REVISION_NUMBER ": %ld\n", revision)); SVN_ERR(svn_rdump__normalize_props(&normal_props, rev_props, pool)); propstring = svn_stringbuf_create_ensure(0, pool); revprop_stream = svn_stream_from_stringbuf(propstring, pool); SVN_ERR(svn_hash_write2(normal_props, revprop_stream, "PROPS-END", pool)); SVN_ERR(svn_stream_close(revprop_stream)); /* Prop-content-length: 13 */ SVN_ERR(svn_stream_printf(stdout_stream, pool, SVN_REPOS_DUMPFILE_PROP_CONTENT_LENGTH ": %" APR_SIZE_T_FMT "\n", propstring->len)); /* Content-length: 29 */ SVN_ERR(svn_stream_printf(stdout_stream, pool, SVN_REPOS_DUMPFILE_CONTENT_LENGTH ": %" APR_SIZE_T_FMT "\n\n", propstring->len)); /* Property data. */ SVN_ERR(svn_stream_write(stdout_stream, propstring->data, &(propstring->len))); SVN_ERR(svn_stream_printf(stdout_stream, pool, "\n")); SVN_ERR(svn_stream_close(stdout_stream)); SVN_ERR(svn_rdump__get_dump_editor(editor, edit_baton, revision, rb->stdout_stream, rb->extra_ra_session, check_cancel, NULL, pool)); return SVN_NO_ERROR; }
void Client::get(Path & dstPath, const Path & path, const Revision & revision, const Revision & peg_revision) throw(ClientException) { Pool pool; // create a new file and suppose we only want // this users to be able to read and write the file apr_file_t * file = openTempFile(dstPath, path, revision, pool); // now create a stream and let svn_client_cat write to the // stream svn_stream_t * stream = svn_stream_from_aprfile(file, pool); if (stream != 0) { svn_error_t * error = svn_client_cat2( stream, path.c_str(), peg_revision.revision() , revision.revision(), *m_context, pool); if (error != 0) throw ClientException(error); svn_stream_close(stream); } // finalize stuff apr_file_close(file); }
static svn_error_t * test_stream_base64(apr_pool_t *pool) { svn_stream_t *stream; svn_stringbuf_t *actual = svn_stringbuf_create_empty(pool); svn_stringbuf_t *expected = svn_stringbuf_create_empty(pool); int i; static const char *strings[] = { "fairly boring test data... blah blah", "A", "abc", "012345679", NULL }; stream = svn_stream_from_stringbuf(actual, pool); stream = svn_base64_decode(stream, pool); stream = svn_base64_encode(stream, pool); for (i = 0; strings[i]; i++) { apr_size_t len = strlen(strings[i]); svn_stringbuf_appendbytes(expected, strings[i], len); SVN_ERR(svn_stream_write(stream, strings[i], &len)); } SVN_ERR(svn_stream_close(stream)); SVN_TEST_STRING_ASSERT(actual->data, expected->data); return SVN_NO_ERROR; }
svn_error_t * svn_fs_file_checksum(svn_checksum_t **checksum, svn_checksum_kind_t kind, svn_fs_root_t *root, const char *path, svn_boolean_t force, apr_pool_t *pool) { SVN_ERR(root->vtable->file_checksum(checksum, kind, root, path, pool)); if (force && (*checksum == NULL || (*checksum)->kind != kind)) { svn_stream_t *contents, *checksum_contents; SVN_ERR(svn_fs_file_contents(&contents, root, path, pool)); checksum_contents = svn_stream_checksummed2(contents, checksum, NULL, kind, TRUE, pool); /* This will force a read of any remaining data (which is all of it in this case) and dump the checksum into checksum->digest. */ SVN_ERR(svn_stream_close(checksum_contents)); } return SVN_NO_ERROR; }
static svn_error_t * parse_spool_file(svn_ra_neon__session_t *ras, const char *spool_file_name, ne_xml_parser *success_parser, apr_pool_t *pool) { svn_stream_t *spool_stream; char *buf = apr_palloc(pool, SVN__STREAM_CHUNK_SIZE); apr_size_t len; SVN_ERR(svn_stream_open_readonly(&spool_stream, spool_file_name, pool, pool)); while (1) { if (ras->callbacks && ras->callbacks->cancel_func) SVN_ERR((ras->callbacks->cancel_func)(ras->callback_baton)); len = SVN__STREAM_CHUNK_SIZE; SVN_ERR(svn_stream_read(spool_stream, buf, &len)); if (len > 0) if (ne_xml_parse(success_parser, buf, len) != 0) /* The parse encountered an error or was aborted by a user defined callback */ break; if (len != SVN__STREAM_CHUNK_SIZE) break; } return svn_stream_close(spool_stream); }
svn_error_t * svn_string_from_stream(svn_string_t **result, svn_stream_t *stream, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { svn_stringbuf_t *work = svn_stringbuf_create_ensure(SVN__STREAM_CHUNK_SIZE, result_pool); char *buffer = apr_palloc(scratch_pool, SVN__STREAM_CHUNK_SIZE); while (1) { apr_size_t len = SVN__STREAM_CHUNK_SIZE; SVN_ERR(svn_stream_read(stream, buffer, &len)); svn_stringbuf_appendbytes(work, buffer, len); if (len < SVN__STREAM_CHUNK_SIZE) break; } SVN_ERR(svn_stream_close(stream)); *result = apr_palloc(result_pool, sizeof(**result)); (*result)->data = work->data; (*result)->len = work->len; return SVN_NO_ERROR; }
static svn_error_t * close_handler_checksum(void *baton) { struct checksum_stream_baton *btn = baton; /* If we're supposed to drain the stream, do so before finalizing the checksum. */ if (btn->read_more) { char *buf = apr_palloc(btn->pool, SVN__STREAM_CHUNK_SIZE); apr_size_t len = SVN__STREAM_CHUNK_SIZE; do { SVN_ERR(read_handler_checksum(baton, buf, &len)); } while (btn->read_more); } if (btn->read_ctx) SVN_ERR(svn_checksum_final(btn->read_checksum, btn->read_ctx, btn->pool)); if (btn->write_ctx) SVN_ERR(svn_checksum_final(btn->write_checksum, btn->write_ctx, btn->pool)); return svn_error_trace(svn_stream_close(btn->proxy)); }
/* Helper for svn_repos_dump_fs. Write a revision record of REV in FS to writable STREAM, using POOL. */ static svn_error_t * write_revision_record(svn_stream_t *stream, svn_fs_t *fs, svn_revnum_t rev, apr_pool_t *pool) { apr_size_t len; apr_hash_t *props; svn_stringbuf_t *encoded_prophash; apr_time_t timetemp; svn_string_t *datevalue; svn_stream_t *propstream; /* Read the revision props even if we're aren't going to dump them for verification purposes */ SVN_ERR(svn_fs_revision_proplist(&props, fs, rev, pool)); /* Run revision date properties through the time conversion to canonicalize them. */ /* ### Remove this when it is no longer needed for sure. */ datevalue = apr_hash_get(props, SVN_PROP_REVISION_DATE, APR_HASH_KEY_STRING); if (datevalue) { SVN_ERR(svn_time_from_cstring(&timetemp, datevalue->data, pool)); datevalue = svn_string_create(svn_time_to_cstring(timetemp, pool), pool); apr_hash_set(props, SVN_PROP_REVISION_DATE, APR_HASH_KEY_STRING, datevalue); } encoded_prophash = svn_stringbuf_create_ensure(0, pool); propstream = svn_stream_from_stringbuf(encoded_prophash, pool); SVN_ERR(svn_hash_write2(props, propstream, "PROPS-END", pool)); SVN_ERR(svn_stream_close(propstream)); /* ### someday write a revision-content-checksum */ SVN_ERR(svn_stream_printf(stream, pool, SVN_REPOS_DUMPFILE_REVISION_NUMBER ": %ld\n", rev)); SVN_ERR(svn_stream_printf(stream, pool, SVN_REPOS_DUMPFILE_PROP_CONTENT_LENGTH ": %" APR_SIZE_T_FMT "\n", encoded_prophash->len)); /* Write out a regular Content-length header for the benefit of non-Subversion RFC-822 parsers. */ SVN_ERR(svn_stream_printf(stream, pool, SVN_REPOS_DUMPFILE_CONTENT_LENGTH ": %" APR_SIZE_T_FMT "\n\n", encoded_prophash->len)); len = encoded_prophash->len; SVN_ERR(svn_stream_write(stream, encoded_prophash->data, &len)); len = 1; return svn_stream_write(stream, "\n", &len); }
static svn_error_t * store_and_load_table(string_table_t **table, apr_pool_t *pool) { svn_stringbuf_t *stream_buffer = svn_stringbuf_create_empty(pool); svn_stream_t *stream; stream = svn_stream_from_stringbuf(stream_buffer, pool); SVN_ERR(svn_fs_x__write_string_table(stream, *table, pool)); SVN_ERR(svn_stream_close(stream)); *table = NULL; stream = svn_stream_from_stringbuf(stream_buffer, pool); SVN_ERR(svn_fs_x__read_string_table(table, stream, pool, pool)); SVN_ERR(svn_stream_close(stream)); return SVN_NO_ERROR; }
/* Implements svn_close_fn_t */ static svn_error_t * close_handler_lazyopen(void *baton) { lazyopen_baton_t *b = baton; if (b->real_stream != NULL) SVN_ERR(svn_stream_close(b->real_stream)); return SVN_NO_ERROR; }
svn_error_t *svn_stream_copy3(svn_stream_t *from, svn_stream_t *to, svn_cancel_func_t cancel_func, void *cancel_baton, apr_pool_t *scratch_pool) { char *buf = apr_palloc(scratch_pool, SVN__STREAM_CHUNK_SIZE); svn_error_t *err; svn_error_t *err2; /* Read and write chunks until we get a short read, indicating the end of the stream. (We can't get a short write without an associated error.) */ while (1) { apr_size_t len = SVN__STREAM_CHUNK_SIZE; if (cancel_func) { err = cancel_func(cancel_baton); if (err) break; } err = svn_stream_read(from, buf, &len); if (err) break; if (len > 0) err = svn_stream_write(to, buf, &len); if (err || (len != SVN__STREAM_CHUNK_SIZE)) break; } err2 = svn_error_compose_create(svn_stream_close(from), svn_stream_close(to)); return svn_error_compose_create(err, err2); }
/* Copies the data from ORIGINAL_STREAM to a temporary file, returning both the original and compressed size. */ static svn_error_t * create_compressed(apr_file_t **result, svn_filesize_t *full_size, svn_filesize_t *compressed_size, svn_stream_t *original_stream, svn_cancel_func_t cancel_func, void *cancel_baton, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { svn_stream_t *compressed; svn_filesize_t bytes_read = 0; apr_size_t rd; SVN_ERR(svn_io_open_uniquely_named(result, NULL, NULL, "diffgz", NULL, svn_io_file_del_on_pool_cleanup, result_pool, scratch_pool)); compressed = svn_stream_compressed( svn_stream_from_aprfile2(*result, TRUE, scratch_pool), scratch_pool); if (original_stream) do { char buffer[SVN__STREAM_CHUNK_SIZE]; rd = sizeof(buffer); if (cancel_func) SVN_ERR(cancel_func(cancel_baton)); SVN_ERR(svn_stream_read_full(original_stream, buffer, &rd)); bytes_read += rd; SVN_ERR(svn_stream_write(compressed, buffer, &rd)); } while(rd == SVN__STREAM_CHUNK_SIZE); else { apr_size_t zero = 0; SVN_ERR(svn_stream_write(compressed, NULL, &zero)); } SVN_ERR(svn_stream_close(compressed)); /* Flush compression */ *full_size = bytes_read; SVN_ERR(svn_io_file_size_get(compressed_size, *result, scratch_pool)); return SVN_NO_ERROR; }
svn_error_t * svn_fs_x__close_revision_file(svn_fs_x__revision_file_t *file) { if (file->stream) SVN_ERR(svn_stream_close(file->stream)); if (file->file) SVN_ERR(svn_io_file_close(file->file, file->pool)); file->file = NULL; file->stream = NULL; file->l2p_stream = NULL; file->p2l_stream = NULL; return SVN_NO_ERROR; }
svn_error_t * svn_stream_contents_same2(svn_boolean_t *same, svn_stream_t *stream1, svn_stream_t *stream2, apr_pool_t *pool) { char *buf1 = apr_palloc(pool, SVN__STREAM_CHUNK_SIZE); char *buf2 = apr_palloc(pool, SVN__STREAM_CHUNK_SIZE); apr_size_t bytes_read1 = SVN__STREAM_CHUNK_SIZE; apr_size_t bytes_read2 = SVN__STREAM_CHUNK_SIZE; svn_error_t *err = NULL; *same = TRUE; /* assume TRUE, until disproved below */ while (bytes_read1 == SVN__STREAM_CHUNK_SIZE && bytes_read2 == SVN__STREAM_CHUNK_SIZE) { err = svn_stream_read(stream1, buf1, &bytes_read1); if (err) break; err = svn_stream_read(stream2, buf2, &bytes_read2); if (err) break; if ((bytes_read1 != bytes_read2) || (memcmp(buf1, buf2, bytes_read1))) { *same = FALSE; break; } } return svn_error_compose_create(err, svn_error_compose_create( svn_stream_close(stream1), svn_stream_close(stream2))); }
svn_error_t * svn_wc__write_old_wcprops(const char *path, apr_hash_t *prophash, svn_node_kind_t kind, apr_pool_t *scratch_pool) { apr_pool_t *pool = scratch_pool; const char *parent_dir; const char *base_name; svn_stream_t *stream; const char *temp_dir_path; const char *temp_prop_path; const char *prop_path; int wc_format_version; if (kind == svn_node_dir) parent_dir = path; else svn_path_split(path, &parent_dir, &base_name, pool); /* At this point, we know we need to open a file in the admin area of parent_dir. First check that parent_dir is a working copy: */ SVN_ERR(svn_wc_check_wc(parent_dir, &wc_format_version, pool)); if (wc_format_version == 0) return svn_error_createf(SVN_ERR_WC_OBSTRUCTED_UPDATE, NULL, _("'%s' is not a working copy"), svn_path_local_style(parent_dir, pool)); /* Write to a temp file, then rename into place. */ temp_dir_path = svn_wc__adm_child(parent_dir, SVN_WC__ADM_TMP, pool); SVN_ERR(svn_stream_open_unique(&stream, &temp_prop_path, temp_dir_path, svn_io_file_del_none, pool, pool)); SVN_ERR_W(svn_hash_write2(prophash, stream, SVN_HASH_TERMINATOR, pool), apr_psprintf(pool, _("Cannot write property hash for '%s'"), svn_path_local_style(path, pool))); svn_stream_close(stream); /* Close file, then do an atomic "move". */ SVN_ERR(svn_wc__prop_path(&prop_path, path, kind, svn_wc__props_wcprop, pool)); SVN_ERR(svn_io_file_rename(temp_prop_path, prop_path, pool)); return svn_io_set_file_read_only(prop_path, FALSE, pool); }
static svn_error_t * close_handler_md5(void *baton) { struct md5_stream_baton *btn = baton; SVN_ERR(svn_stream_close(btn->proxy)); if (btn->read_digest) *btn->read_digest = apr_pmemdup(btn->pool, btn->read_checksum->digest, APR_MD5_DIGESTSIZE); if (btn->write_digest) *btn->write_digest = apr_pmemdup(btn->pool, btn->write_checksum->digest, APR_MD5_DIGESTSIZE); return SVN_NO_ERROR; }
static svn_error_t *ra_svn_handle_textdelta_end(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *token; ra_svn_token_entry_t *entry; /* Parse arguments and look up the token. */ SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "c", &token)); SVN_ERR(lookup_token(ds, token, TRUE, &entry)); if (!entry->dstream) return svn_error_create(SVN_ERR_RA_SVN_MALFORMED_DATA, NULL, _("Apply-textdelta not active")); SVN_CMD_ERR(svn_stream_close(entry->dstream)); entry->dstream = NULL; svn_pool_destroy(entry->pool); return SVN_NO_ERROR; }
svn_error_t * svn_config_read_auth_data(apr_hash_t **hash, const char *cred_kind, const char *realmstring, const char *config_dir, apr_pool_t *pool) { svn_node_kind_t kind; const char *auth_path; *hash = NULL; SVN_ERR(svn_auth__file_path(&auth_path, cred_kind, realmstring, config_dir, pool)); if (! auth_path) return SVN_NO_ERROR; SVN_ERR(svn_io_check_path(auth_path, &kind, pool)); if (kind == svn_node_file) { svn_stream_t *stream; svn_string_t *stored_realm; SVN_ERR_W(svn_stream_open_readonly(&stream, auth_path, pool, pool), _("Unable to open auth file for reading")); *hash = apr_hash_make(pool); SVN_ERR_W(svn_hash_read2(*hash, stream, SVN_HASH_TERMINATOR, pool), apr_psprintf(pool, _("Error parsing '%s'"), svn_dirent_local_style(auth_path, pool))); stored_realm = svn_hash_gets(*hash, SVN_CONFIG_REALMSTRING_KEY); if (!stored_realm || strcmp(stored_realm->data, realmstring) != 0) *hash = NULL; /* Hash collision, or somebody tampering with storage */ SVN_ERR(svn_stream_close(stream)); } return SVN_NO_ERROR; }
/* Read a dumpstream from stdin, and use it to feed a loader capable * of transmitting that information to the repository located at URL * (to which SESSION has been opened). AUX_SESSION is a second RA * session opened to the same URL for performing auxiliary out-of-band * operations. */ static svn_error_t * load_revisions(svn_ra_session_t *session, svn_ra_session_t *aux_session, const char *url, svn_boolean_t quiet, apr_pool_t *pool) { apr_file_t *stdin_file; svn_stream_t *stdin_stream; apr_file_open_stdin(&stdin_file, pool); stdin_stream = svn_stream_from_aprfile2(stdin_file, FALSE, pool); SVN_ERR(svn_rdump__load_dumpstream(stdin_stream, session, aux_session, quiet, check_cancel, NULL, pool)); SVN_ERR(svn_stream_close(stdin_stream)); return SVN_NO_ERROR; }
svn_error_t * svn_config_write_auth_data(apr_hash_t *hash, const char *cred_kind, const char *realmstring, const char *config_dir, apr_pool_t *pool) { apr_file_t *authfile = NULL; svn_stream_t *stream; const char *auth_path; SVN_ERR(svn_auth__file_path(&auth_path, cred_kind, realmstring, config_dir, pool)); if (! auth_path) return svn_error_create(SVN_ERR_NO_AUTH_FILE_PATH, NULL, _("Unable to locate auth file")); /* Add the realmstring to the hash, so programs (or users) can verify exactly which set of credentials this file holds. */ svn_hash_sets(hash, SVN_CONFIG_REALMSTRING_KEY, svn_string_create(realmstring, pool)); SVN_ERR_W(svn_io_file_open(&authfile, auth_path, (APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BUFFERED), APR_OS_DEFAULT, pool), _("Unable to open auth file for writing")); stream = svn_stream_from_aprfile2(authfile, FALSE, pool); SVN_ERR_W(svn_hash_write2(hash, stream, SVN_HASH_TERMINATOR, pool), apr_psprintf(pool, _("Error writing hash to '%s'"), svn_dirent_local_style(auth_path, pool))); SVN_ERR(svn_stream_close(stream)); /* To be nice, remove the realmstring from the hash again, just in case the caller wants their hash unchanged. */ svn_hash_sets(hash, SVN_CONFIG_REALMSTRING_KEY, NULL); return SVN_NO_ERROR; }
svn_error_t * svn_wc__close_adm_stream(svn_stream_t *stream, const char *temp_file_path, const char *path, const char *fname, apr_pool_t *scratch_pool) { const char *tmp_path = extend_with_adm_name(path, NULL, TRUE, scratch_pool, fname, NULL); const char *dst_path = extend_with_adm_name(path, NULL, FALSE, scratch_pool, fname, NULL); /* ### eventually, just use the parameter rather than compute tmp_path */ SVN_ERR_ASSERT(strcmp(temp_file_path, tmp_path) == 0); SVN_ERR(svn_stream_close(stream)); /* Put the completed file into its intended location. */ SVN_ERR(svn_io_file_rename(tmp_path, dst_path, scratch_pool)); return svn_io_set_file_read_only(dst_path, FALSE, scratch_pool); }
svn_error_t * svn_config_write_auth_data(apr_hash_t *hash, const char *cred_kind, const char *realmstring, const char *config_dir, apr_pool_t *pool) { svn_stream_t *stream; const char *auth_path, *tmp_path; SVN_ERR(svn_auth__file_path(&auth_path, cred_kind, realmstring, config_dir, pool)); if (! auth_path) return svn_error_create(SVN_ERR_NO_AUTH_FILE_PATH, NULL, _("Unable to locate auth file")); /* Add the realmstring to the hash, so programs (or users) can verify exactly which set of credentials this file holds. ### What if realmstring key is already in the hash? */ svn_hash_sets(hash, SVN_CONFIG_REALMSTRING_KEY, svn_string_create(realmstring, pool)); SVN_ERR_W(svn_stream_open_unique(&stream, &tmp_path, svn_dirent_dirname(auth_path, pool), svn_io_file_del_on_pool_cleanup, pool, pool), _("Unable to open auth file for writing")); SVN_ERR_W(svn_hash_write2(hash, stream, SVN_HASH_TERMINATOR, pool), apr_psprintf(pool, _("Error writing hash to '%s'"), svn_dirent_local_style(auth_path, pool))); SVN_ERR(svn_stream_close(stream)); SVN_ERR(svn_io_file_rename2(tmp_path, auth_path, FALSE, pool)); /* To be nice, remove the realmstring from the hash again, just in case the caller wants their hash unchanged. ### Should we also do this when a write error occurs? */ svn_hash_sets(hash, SVN_CONFIG_REALMSTRING_KEY, NULL); return SVN_NO_ERROR; }
static svn_error_t * test_stream_seek_stringbuf(apr_pool_t *pool) { svn_stream_t *stream; svn_stringbuf_t *stringbuf; char buf[4]; apr_size_t len; svn_stream_mark_t *mark; stringbuf = svn_stringbuf_create("OneTwo", pool); stream = svn_stream_from_stringbuf(stringbuf, pool); len = 3; SVN_ERR(svn_stream_read_full(stream, buf, &len)); buf[3] = '\0'; SVN_TEST_STRING_ASSERT(buf, "One"); SVN_ERR(svn_stream_mark(stream, &mark, pool)); len = 3; SVN_ERR(svn_stream_read_full(stream, buf, &len)); buf[3] = '\0'; SVN_TEST_STRING_ASSERT(buf, "Two"); SVN_ERR(svn_stream_seek(stream, mark)); len = 3; SVN_ERR(svn_stream_read_full(stream, buf, &len)); buf[3] = '\0'; SVN_TEST_STRING_ASSERT(buf, "Two"); /* Go back to the begin of last word and try to skip some of it */ SVN_ERR(svn_stream_seek(stream, mark)); SVN_ERR(svn_stream_skip(stream, 2)); /* The remaining line should be empty */ len = 3; SVN_ERR(svn_stream_read_full(stream, buf, &len)); buf[len] = '\0'; SVN_TEST_ASSERT(len == 1); SVN_TEST_STRING_ASSERT(buf, "o"); SVN_ERR(svn_stream_close(stream)); return SVN_NO_ERROR; }
bool CAppUtils::CreateUnifiedDiff(const CString& orig, const CString& modified, const CString& output, bool bShowError) { apr_file_t * outfile = NULL; apr_pool_t * pool = svn_pool_create(NULL); svn_error_t * err = svn_io_file_open (&outfile, svn_path_internal_style(CUnicodeUtils::GetUTF8(output), pool), APR_WRITE | APR_CREATE | APR_BINARY | APR_TRUNCATE, APR_OS_DEFAULT, pool); if (err == NULL) { svn_stream_t * stream = svn_stream_from_aprfile2(outfile, false, pool); if (stream) { svn_diff_t * diff = NULL; svn_diff_file_options_t * opts = svn_diff_file_options_create(pool); opts->ignore_eol_style = false; opts->ignore_space = svn_diff_file_ignore_space_none; err = svn_diff_file_diff_2(&diff, svn_path_internal_style(CUnicodeUtils::GetUTF8(orig), pool), svn_path_internal_style(CUnicodeUtils::GetUTF8(modified), pool), opts, pool); if (err == NULL) { err = svn_diff_file_output_unified(stream, diff, svn_path_internal_style(CUnicodeUtils::GetUTF8(orig), pool), svn_path_internal_style(CUnicodeUtils::GetUTF8(modified), pool), NULL, NULL, pool); svn_stream_close(stream); } } apr_file_close(outfile); } if (err) { if (bShowError) AfxMessageBox(CAppUtils::GetErrorString(err), MB_ICONERROR); svn_error_clear(err); svn_pool_destroy(pool); return false; } svn_pool_destroy(pool); return true; }
static svn_error_t * test_stream_compressed_empty_file(apr_pool_t *pool) { svn_stream_t *stream, *empty_file_stream; char buf[1]; apr_size_t len; /* Reading an empty file with a compressed stream should not error. */ SVN_ERR(svn_stream_open_unique(&empty_file_stream, NULL, NULL, svn_io_file_del_on_pool_cleanup, pool, pool)); stream = svn_stream_compressed(empty_file_stream, pool); len = sizeof(buf); SVN_ERR(svn_stream_read_full(stream, buf, &len)); if (len > 0) return svn_error_create(SVN_ERR_TEST_FAILED, NULL, "Got unexpected result."); SVN_ERR(svn_stream_close(stream)); return SVN_NO_ERROR; }
/* Print a revision record header for REVISION to STDOUT_STREAM. Use * SESSION to contact the repository for revision properties and * such. */ static svn_error_t * dump_revision_header(svn_ra_session_t *session, svn_stream_t *stdout_stream, svn_revnum_t revision, apr_pool_t *pool) { apr_hash_t *prophash; svn_stringbuf_t *propstring; svn_stream_t *propstream; SVN_ERR(svn_stream_printf(stdout_stream, pool, SVN_REPOS_DUMPFILE_REVISION_NUMBER ": %ld\n", revision)); prophash = apr_hash_make(pool); propstring = svn_stringbuf_create_empty(pool); SVN_ERR(svn_ra_rev_proplist(session, revision, &prophash, pool)); propstream = svn_stream_from_stringbuf(propstring, pool); SVN_ERR(svn_hash_write2(prophash, propstream, "PROPS-END", pool)); SVN_ERR(svn_stream_close(propstream)); /* Property-content-length: 14; Content-length: 14 */ SVN_ERR(svn_stream_printf(stdout_stream, pool, SVN_REPOS_DUMPFILE_PROP_CONTENT_LENGTH ": %" APR_SIZE_T_FMT "\n", propstring->len)); SVN_ERR(svn_stream_printf(stdout_stream, pool, SVN_REPOS_DUMPFILE_CONTENT_LENGTH ": %" APR_SIZE_T_FMT "\n\n", propstring->len)); /* The properties */ SVN_ERR(svn_stream_write(stdout_stream, propstring->data, &(propstring->len))); SVN_ERR(svn_stream_printf(stdout_stream, pool, "\n")); return SVN_NO_ERROR; }