我正在使用PEAR/VersionControl_SVN
库进行subversion。这个库的优点是它是subversion命令行客户端的包装器。因此,我不需要安装任何绑定/模块/扩展(例如svn extension)以便使用嵌入式函数(例如svn_ls
或svn_commit
)直接使用subversion。我的所有应用程序运行需求都是安装了subversion命令行客户端。不好的是,如果使用subversion命令行客户端无法完成某些操作,则无法使用此库。
例如,我找不到任何其他方法来检查用户是否具有对存储库的可写访问权限,除了尝试创建和删除/test
目录然后分析输出:
require_once 'VersionControl/SVN.php';
class SvnException extends Exception {};
function checkCredentials($url, $user, $password) {
$switches = array(
'username' => $user,
'password' => $password,
'message' => 'check whether user '.$user.' has repository writable access'
);
$svnerror = &PEAR_ErrorStack::singleton('VersionControl_SVN');
$svnoptions = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ARRAY);
$action = VersionControl_SVN::factory('mkdir', $svnoptions);
$url = rtrim($url, '/\ ');
$action->run(array($url.'/test'), $switches);
$action = VersionControl_SVN::factory('delete', $svnoptions);
$action->run(array($url.'/test'), $switches);
if($errors = $svnerror->getErrors()) {
$all_errors = '';
foreach ($errors as $err) {
$all_errors .= $err['message']."\n";
}
throw new SvnException($all_errors);
}
return true;
}
$url = 'svn://localhost:3129';
$user = 'username';
$password = 'password';
try {
if(checkCredentials($url, $user, $password)) {
print "User $user has writable access to subversion repository $url\n";
}
} catch (SvnException $e) {
print "User $user does not have writable access to subversion repository $url\n";
print $e->getMessage();
}
输出如下:
> php checksvnaccess.php
User username does not have writable access to subversion repository svn://localhost:3129
svn: E160013: URL 'svn://localhost:3129/test' does not exist (cmd: "C:\Program F
iles\Subversion Client\svn.EXE" delete --username username --password password -
-message "check whether user username has repository writable access" "svn://loc
alhost:3129/test")
svn: E170001: SASL authentication error: SASL(-1): generic failure: Unable to fi
nd a callback: 2 (cmd: "C:\Program Files\Subversion Client\svn.EXE" mkdir --user
name username --password password --message "check whether user username has rep
ository writable access" "svn://localhost:3129/test")
Username: Password for '': (cmd: "C:\Program Files\Subversion Client\svn.EXE" mk
dir --username username --password password --message "check whether user userna
me has repository writable access" "svn://localhost:3129/test")
Authentication realm: <svn://localhost:3129> 76572ec9-2173-de46-8e99-8db01e97341
a (cmd: "C:\Program Files\Subversion Client\svn.EXE" mkdir --username username -
-password password --message "check whether user username has repository writabl
e access" "svn://localhost:3129/test")
执行此代码示例与运行以下命令相同:
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"
有没有办法在不尝试在存储库中创建某个对象的情况下使用此库检查存储库访问权限?如果有办法使用命令行检查访问权限会很棒。例如,svn checkaccess --username username --password password svn://localhost:3129/test
。有没有解决方法?