You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by iv...@apache.org on 2015/05/27 12:14:21 UTC
svn commit: r1681954 - in /subversion/trunk/subversion: include/svn_io.h
libsvn_subr/io.c tests/libsvn_subr/io-test.c
Author: ivan
Date: Wed May 27 10:14:21 2015
New Revision: 1681954
URL: http://svn.apache.org/r1681954
Log:
Add new svn_io_file_size_get() function: lightweight variant of
svn_io_file_info_get() that returns only filesize of opened file.
* subversion/libsvn_subr/io.c
* subversion/include/svn_io.h
(svn_io_file_size_get): New.
* subversion/tests/libsvn_subr/io-test.c
(test_file_size_get): New test for svn_io_file_size_get() function.
(test_funcs): Add test_file_size_get to test list.
Modified:
subversion/trunk/subversion/include/svn_io.h
subversion/trunk/subversion/libsvn_subr/io.c
subversion/trunk/subversion/tests/libsvn_subr/io-test.c
Modified: subversion/trunk/subversion/include/svn_io.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_io.h?rev=1681954&r1=1681953&r2=1681954&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_io.h (original)
+++ subversion/trunk/subversion/include/svn_io.h Wed May 27 10:14:21 2015
@@ -2175,6 +2175,18 @@ svn_io_file_info_get(apr_finfo_t *finfo,
apr_pool_t *pool);
+/** Set @a *filesize_p to the size of @a file. Use @a pool for temporary
+ * allocations.
+ *
+ * @note Use svn_io_file_info_get() to get more information about
+ * apr_file_t.
+ *
+ * @since New in 1.10
+ */
+svn_error_t *
+svn_io_file_size_get(svn_filesize_t *filesize_p, apr_file_t *file,
+ apr_pool_t *pool);
+
/** Wrapper for apr_file_read(). */
svn_error_t *
svn_io_file_read(apr_file_t *file,
Modified: subversion/trunk/subversion/libsvn_subr/io.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/io.c?rev=1681954&r1=1681953&r2=1681954&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/io.c (original)
+++ subversion/trunk/subversion/libsvn_subr/io.c Wed May 27 10:14:21 2015
@@ -3582,6 +3582,16 @@ svn_io_file_info_get(apr_finfo_t *finfo,
pool);
}
+svn_error_t *
+svn_io_file_size_get(svn_filesize_t *filesize_p, apr_file_t *file,
+ apr_pool_t *pool)
+{
+ apr_finfo_t finfo;
+ SVN_ERR(svn_io_file_info_get(&finfo, APR_FINFO_SIZE, file, pool));
+
+ *filesize_p = finfo.size;
+ return SVN_NO_ERROR;
+}
svn_error_t *
svn_io_file_read(apr_file_t *file, void *buf,
Modified: subversion/trunk/subversion/tests/libsvn_subr/io-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/io-test.c?rev=1681954&r1=1681953&r2=1681954&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/io-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/io-test.c Wed May 27 10:14:21 2015
@@ -782,7 +782,47 @@ test_install_stream_to_longpath(apr_pool
return SVN_NO_ERROR;
}
-
+
+static svn_error_t *
+test_file_size_get(apr_pool_t *pool)
+{
+ const char *tmp_dir, *path;
+ apr_file_t *file;
+ svn_filesize_t filesize;
+
+ /* Create an empty directory. */
+ SVN_ERR(svn_dirent_get_absolute(&tmp_dir, "test_file_size_get", pool));
+ SVN_ERR(svn_io_remove_dir2(tmp_dir, TRUE, NULL, NULL, pool));
+ SVN_ERR(svn_io_make_dir_recursively(tmp_dir, pool));
+ svn_test_add_dir_cleanup(tmp_dir);
+
+ /* Path does not exist. */
+ path = svn_dirent_join(tmp_dir, "file", pool);
+
+ /* Create a file.*/
+ SVN_ERR(svn_io_file_open(&file, path,
+ APR_WRITE | APR_CREATE | APR_BUFFERED,
+ APR_OS_DEFAULT, pool));
+ SVN_ERR(svn_io_file_size_get(&filesize, file, pool));
+ SVN_TEST_ASSERT(filesize == 0);
+
+ /* Write 8 bytes and check new size. */
+ SVN_ERR(svn_io_file_write_full(file, "12345678", 8, NULL, pool));
+
+ SVN_ERR(svn_io_file_size_get(&filesize, file, pool));
+ SVN_TEST_ASSERT(filesize == 8);
+
+ /* Truncate to 2 bytes. */
+ SVN_ERR(svn_io_file_trunc(file, 2, pool));
+
+ SVN_ERR(svn_io_file_size_get(&filesize, file, pool));
+ SVN_TEST_ASSERT(filesize == 2);
+
+ /* Close the file. */
+ SVN_ERR(svn_io_file_close(file, pool));
+ return SVN_NO_ERROR;
+}
+
/* The test table. */
static int max_threads = 3;
@@ -806,6 +846,8 @@ static struct svn_test_descriptor_t test
"test ignore-enoent"),
SVN_TEST_PASS2(test_install_stream_to_longpath,
"test svn_stream__install_stream to long path"),
+ SVN_TEST_PASS2(test_file_size_get,
+ "test svn_io_file_size_get"),
SVN_TEST_NULL
};