Author: rhuijben
Date: Sat Jul 20 22:02:50 2013
New Revision: 1505219
URL: http://svn.apache.org/r1505219
Log:
Apply some tweaks to svn_io_file_create*() after r1505006. Resolve a regression
on writing a NULL buffer.
* subversion/libsvn_subr/io.c
(svn_io_file_create_binary): Try to delete the file we created on error
writing it. Use standard notation for function prototype.
(svn_io_file_create): Resolve regression introduced in r1505006, where a
NULL contents of 0 length would previously not segfault, but now will.
Use standard notation for function prototype.
(svn_io_file_create,
svn_io_dir_file_copy): Use standard notation for function prototype.
Add svn_error_trace.
Modified:
subversion/trunk/subversion/libsvn_subr/io.c
Modified: subversion/trunk/subversion/libsvn_subr/io.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/io.c?rev=1505219&r1=1505218&r2=1505219&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/io.c (original)
+++ subversion/trunk/subversion/libsvn_subr/io.c Sat Jul 20 22:02:50 2013
@@ -1166,10 +1166,11 @@ svn_io_make_dir_recursively(const char *
return SVN_NO_ERROR;
}
-svn_error_t *svn_io_file_create_binary(const char *file,
- const char *contents,
- apr_size_t length,
- apr_pool_t *pool)
+svn_error_t *
+svn_io_file_create_binary(const char *file,
+ const char *contents,
+ apr_size_t length,
+ apr_pool_t *pool)
{
apr_file_t *f;
apr_size_t written;
@@ -1182,34 +1183,54 @@ svn_error_t *svn_io_file_create_binary(c
if (length)
err = svn_io_file_write_full(f, contents, length, &written, pool);
- return svn_error_trace(
- svn_error_compose_create(err,
- svn_io_file_close(f, pool)));
+ err = svn_error_compose_create(
+ err,
+ svn_io_file_close(f, pool));
+
+ if (err)
+ {
+ /* Our caller doesn't know if we left a file or not if we return
+ an error. Better to cleanup after ourselves if we created the
+ file. */
+ return svn_error_trace(
+ svn_error_compose_create(
+ err,
+ svn_io_remove_file2(file, TRUE, pool)));
+ }
+
+ return SVN_NO_ERROR;
}
-svn_error_t *svn_io_file_create(const char *file,
- const char *contents,
- apr_pool_t *pool)
+svn_error_t *
+svn_io_file_create(const char *file,
+ const char *contents,
+ apr_pool_t *pool)
{
return svn_error_trace(svn_io_file_create_binary(file, contents,
- strlen(contents), pool));
+ contents
+ ? strlen(contents)
+ : 0,
+ pool));
}
-svn_error_t *svn_io_file_create_empty(const char *file,
- apr_pool_t *pool)
+svn_error_t *
+svn_io_file_create_empty(const char *file,
+ apr_pool_t *pool)
{
return svn_error_trace(svn_io_file_create_binary(file, "", 0, pool));
}
-svn_error_t *svn_io_dir_file_copy(const char *src_path,
- const char *dest_path,
- const char *file,
- apr_pool_t *pool)
+svn_error_t *
+svn_io_dir_file_copy(const char *src_path,
+ const char *dest_path,
+ const char *file,
+ apr_pool_t *pool)
{
const char *file_dest_path = svn_dirent_join(dest_path, file, pool);
const char *file_src_path = svn_dirent_join(src_path, file, pool);
- return svn_io_copy_file(file_src_path, file_dest_path, TRUE, pool);
+ return svn_error_trace(
+ svn_io_copy_file(file_src_path, file_dest_path, TRUE, pool));
}