[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn_stream_copy3() in svn_io.h

From: Stefan Sperling <stsp_at_elego.de>
Date: Tue, 7 Apr 2009 12:25:57 +0100

On Tue, Apr 07, 2009 at 07:15:10PM +0800, Edmund Wong wrote:
> Hi,
>
> Again, reading svn_io.h, I came across a "TODO" for the
> svn_stream_copy3() :
>
> * ### TODO: should close the streams ALWAYS, even on error exit
>
> Thinking that it might be my chance to do something for a
> change, I looked into stream.c (this *is* the file, right?)
> and came across the following:-
>
> 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);
>
> /* 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)
> SVN_ERR(cancel_func(cancel_baton));
>
> SVN_ERR(svn_stream_read(from, buf, &len));
> if (len > 0)
> SVN_ERR(svn_stream_write(to, buf, &len));
> if (len != SVN__STREAM_CHUNK_SIZE)
> break;
> }
>
>
> return svn_error_compose_create(svn_stream_close(from),
> svn_stream_close(to));
> }
>
> Does this mean that since svn_stream_copy3() calls
> svn_stream_close() on both from and to, both from
> and to are closed after the return? (Though I'm not sure if
> the resulting closure will result in an error.)
>
> If it does mean so, shouldn't the TODO be 'removed'?

All the SVN_ERR(...) calls might return if an error is
thrown from the function wrapped in SVN_ERR().

So I'd say the TODO is still valid.

Stefan
Received on 2009-04-07 13:26:37 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.