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

Re: [PATCH] Completed TODO: svn_stream_copy3()

From: Edmund Wong <ed_at_kdtc.net>
Date: Fri, 10 Apr 2009 15:55:26 +0800

Hi,

My previous patch contained a mistake which I didn't
see. With this patch, the tests run through to the
end. Of course, this isn't a necessary condition for
it to be the right one.

If len == 0, it doesn't break out of the loop; though
it should break out the next time it tries to read.
I'll need to read up on the stream_read() function.
What happens if it reads past? It should throw
an error, no? And thusly break.

Any clarifications appreciated.

Edmund

Log:

[[[
         Completed the TODO as stated in svn_io.h for
      svn_stream_copy3().

      * subversion/libsvn_subr/stream.c
        (svn_stream_copy3): Even on error exit, the two files
                            from and to are closed.

       Patch by: Edmund Wong <edmund_at_belfordhk.com>

       Review by: mf
]]]

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1626479

Index: subversion/libsvn_subr/stream.c
===================================================================
--- subversion/libsvn_subr/stream.c (revision 37129)
+++ subversion/libsvn_subr/stream.c (working copy)
@@ -210,6 +210,8 @@
                               apr_pool_t *scratch_pool)
 {
   char *buf = apr_palloc(scratch_pool, SVN__STREAM_CHUNK_SIZE);
+ svn_error_t *err = SVN_NO_ERROR;
+ svn_error_t *err2 = SVN_NO_ERROR;
 
   /* 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
@@ -218,18 +220,46 @@
     {
       apr_size_t len = SVN__STREAM_CHUNK_SIZE;
 
- if (cancel_func)
- SVN_ERR(cancel_func(cancel_baton));
+ 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);
 
- 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;
+ if (len != SVN__STREAM_CHUNK_SIZE)
+ break;
+
+ if (err)
+ break;
+ }
+ else
+ {
+ break;
+ }
     }
+
+ if (err)
+ {
+ err2 = svn_error_compose_create(svn_stream_close(from),
+ svn_stream_close(to));
+ }
+ else
+ {
+ err2 = SVN_NO_ERROR;
+ err = svn_error_compose_create(svn_stream_close(from),
+ svn_stream_close(to));
+ }
+
 
- return svn_error_compose_create(svn_stream_close(from),
- svn_stream_close(to));
+ return svn_error_compose_create(err,err2);
 }
 
 svn_error_t *
Received on 2009-04-10 09:56:08 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.