Author: stefan2
Date: Sun Aug 24 23:47:43 2014
New Revision: 1620240
URL: http://svn.apache.org/r1620240
Log:
On the revprop-caching-ng branch: Allow for read-only repositories.
Open the revprop generation file in r/o mode by default and require
write access only upon the first write attempt.
* subversion/libsvn_fs_fs/revprops.c
(close_revprop_generation_file): Move up here.
(ensure_revprop_generation): Add r/o option and re-open the file if
write is requested for the first time.
(read_revprop_generation_file,
write_revprop_generation_file,
has_revprop_cache): Update callers.
Modified:
subversion/branches/revprop-caching-ng/subversion/libsvn_fs_fs/revprops.c
Modified:
subversion/branches/revprop-caching-ng/subversion/libsvn_fs_fs/revprops.c
URL:
http://svn.apache.org/viewvc/subversion/branches/revprop-caching-ng/subversion/libsvn_fs_fs/revprops.c?rev=1620240&r1=1620239&r2=1620240&view=diff
==============================================================================
--- subversion/branches/revprop-caching-ng/subversion/libsvn_fs_fs/revprops.c
(original)
+++ subversion/branches/revprop-caching-ng/subversion/libsvn_fs_fs/revprops.c
Sun Aug 24 23:47:43 2014
@@ -188,37 +188,49 @@ svn_fs_fs__upgrade_cleanup_pack_revprops
* after the crash, reader caches may be stale.
*/
-/* Make sure the revprop_generation member in FS is set.
- * Call only for repos that support revprop caching.
+/* If the revprop generation file in FS is open, close it. This is a no-op
+ * if the file is not open.
*/
static svn_error_t *
-ensure_revprop_generation(svn_fs_t *fs,
- apr_pool_t *scratch_pool)
+close_revprop_generation_file(svn_fs_t *fs,
+ apr_pool_t *scratch_pool)
{
fs_fs_data_t *ffd = fs->fsap_data;
- if (ffd->revprop_generation_file == NULL)
+ if (ffd->revprop_generation_file)
{
- const char *path = svn_fs_fs__path_revprop_generation(fs, scratch_pool);
- SVN_ERR(svn_io_file_open(&ffd->revprop_generation_file, path,
- APR_READ | APR_WRITE, APR_OS_DEFAULT,
- fs->pool));
+ SVN_ERR(svn_io_file_close(ffd->revprop_generation_file, scratch_pool));
+ ffd->revprop_generation_file = NULL;
}
return SVN_NO_ERROR;
}
-/* If the revprop generation file in FS is open, close it. This is a no-op
- * if the file is not open.
+/* Make sure the revprop_generation member in FS is set. If READ_ONLY is
+ * set, open the file w/o write permission if the file is not open yet.
+ * The file is kept open if it has sufficient rights (or more) but will be
+ * closed and re-opened if it provided insufficient access rights.
+ *
+ * Call only for repos that support revprop caching.
*/
static svn_error_t *
-close_revprop_generation_file(svn_fs_t *fs,
- apr_pool_t *scratch_pool)
+ensure_revprop_generation(svn_fs_t *fs,
+ svn_boolean_t read_only,
+ apr_pool_t *scratch_pool)
{
fs_fs_data_t *ffd = fs->fsap_data;
- if (ffd->revprop_generation_file)
+ apr_int32_t flags = read_only ? APR_READ : (APR_READ | APR_WRITE);
+
+ /* Close the current file handle if it has insufficient rights. */
+ if ( ffd->revprop_generation_file
+ && (apr_file_flags_get(ffd->revprop_generation_file) & flags) != flags)
+ SVN_ERR(close_revprop_generation_file(fs, scratch_pool));
+
+ /* If not open already, open with sufficient rights. */
+ if (ffd->revprop_generation_file == NULL)
{
- SVN_ERR(svn_io_file_close(ffd->revprop_generation_file, scratch_pool));
- ffd->revprop_generation_file = NULL;
+ const char *path = svn_fs_fs__path_revprop_generation(fs, scratch_pool);
+ SVN_ERR(svn_io_file_open(&ffd->revprop_generation_file, path,
+ flags, APR_OS_DEFAULT, fs->pool));
}
return SVN_NO_ERROR;
@@ -305,7 +317,7 @@ read_revprop_generation_file(apr_int64_t
/* If we can't even access the data, things are very wrong.
* Don't retry in that case.
*/
- SVN_ERR(ensure_revprop_generation(fs, iterpool));
+ SVN_ERR(ensure_revprop_generation(fs, TRUE, iterpool));
SVN_ERR(svn_io_file_seek(ffd->revprop_generation_file, APR_SET, &offset,
iterpool));
@@ -349,7 +361,7 @@ write_revprop_generation_file(svn_fs_t *
SVN_ERR(checkedsummed_number(&buffer, current, scratch_pool, scratch_pool));
- SVN_ERR(ensure_revprop_generation(fs, scratch_pool));
+ SVN_ERR(ensure_revprop_generation(fs, FALSE, scratch_pool));
SVN_ERR(svn_io_file_seek(ffd->revprop_generation_file, APR_SET, &offset,
scratch_pool));
SVN_ERR(svn_io_file_write_full(ffd->revprop_generation_file, buffer->data,
@@ -430,7 +442,7 @@ has_revprop_cache(svn_fs_t *fs,
return FALSE;
/* try initialize our file-backed infrastructure */
- error = ensure_revprop_generation(fs, scratch_pool);
+ error = ensure_revprop_generation(fs, TRUE, scratch_pool);
if (error)
{
/* failure -> disable revprop cache for good */