检查用户的 subversion 可写访问 [英] Check subversion writable access for user
问题描述
有什么方法可以检查用户是否对某个存储库路径具有可写访问权限?我现在要做的是尝试创建目录,然后将其删除以检查用户是否具有可写访问权限:
Is there any way to check whether user have writable access to some repository path? What I do now is trying to create directory and then delete it to check whether user has writable access:
svn mkdir --username username --password password --message "check whether user username has repository writable access" "svn://localhost:3129/test"
svn delete --username username --password password --message "check whether user username has repository writable access" "svn://localhost:3129/test"
问题在于,这些操作作为应用程序源代码的一部分执行得太频繁.因此,如果用户具有可写访问权限,存储库会收到太多不必要的提交.
The problem is that those operations are performed too often as a part of application source code. And, as a result, repository get too many needless commits in case user has writable access.
是否有任何类似于 svn checkaccess --username username --password password svn://localhost:3129/test
的命令或任何其他解决方法,以便我不需要创建临时目录 all时间?
Is there any command similar to svn checkaccess --username username --password password svn://localhost:3129/test
or any other workarounds so that I would not need to create temporary directory all the time?
推荐答案
我可以提出一种 hacky 方法,但我不确定它是否适用于所有协议(我使用 DAV 进行了测试 --- 它有效,文件:///所有路径都是可写的).
I can propose a hacky way, but I'm not sure it will work for all protocols (I tested with DAV --- it worked, with file:/// all paths are writable).
Subversion 有几个 API.一些语言(至少是 C (libsvn_ra)、Java (SVNKit)、Perl (AlienSVN)) 提供允许使用编辑器调用创建提交的远程 API(我不知道 PHP做).如果您对要检查可写性的 URL 执行以下调用:
Subversion has several APIs. Some languages (at least C (libsvn_ra), Java (SVNKit), Perl (AlienSVN)) provide remote API that allows to create a commit with editor calls (I don't know if PHP does). If you perform the following calls on the URL you want to check writability:
openRoot -1
changeDirProperty customPropertyName custromPropertyValue
closeDir
abortEdit
如果目录可写,此序列不会因为 abortEdit() 调用而执行任何更改.但是对于 DAV,如果不可写,这将失败并显示错误代码 RA_NOT_AUTHORIZED (E170001).
This sequence performs no changes because of abortEdit() call, if the directory is writable. But for DAV this fails with error code RA_NOT_AUTHORIZED (E170001) if not writable.
有一篇文章 展示了如何在 Java 中使用带有 SVN 远程 API 的提交.我认为 PHP 代码看起来很相似.
There's an article that shows how to use commit with SVN remote API in Java. I think PHP code would look similar.
希望它有所帮助(如果不是,那么至少是 Java/C/Perl 开发人员).
Hope it helps (if not you then at least Java/C/Perl developers).
这篇关于检查用户的 subversion 可写访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!