SVNKit:SVNException,同时提交锁定的文件

SVNKit:SVNException,同时提交锁定的文件,svn,commit,svnkit,Svn,Commit,Svnkit,我想提交一个修改过的单个文件。据我所知,我使用以下代码: public static SVNCommitInfo modifyFile(ISVNEditor editor, String dirPath, String filePath, InputStream is, long size) throws SVNException { try { SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();

我想提交一个修改过的单个文件。据我所知,我使用以下代码:

public static SVNCommitInfo modifyFile(ISVNEditor editor, String dirPath, String filePath, InputStream is, long size) throws SVNException {
    try {
       SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); 

        editor.openRoot(-1);
        editor.openDir(dirPath, -1);
        editor.openFile(filePath, -1);
        editor.applyTextDelta(filePath, null);

        String chksm = deltaGenerator.sendDelta(filePath, is, editor, true);

        editor.textDeltaEnd(filePath);
        editor.closeFile(filePath, chksm);                                    

        /*
         * Closes the directory.
         */
        editor.closeDir();
        /*
         * Closes the root directory.
         */
        editor.closeDir();
        return editor.closeEdit();
    } catch (SVNException e) {
        if (editor != null) {
            try {
                editor.abortEdit();
            } catch (Exception ex) {
            }
        }    
        throw e;
    }
}
但不幸的是,尽管提交是由拥有外观的用户完成的,但我还是得到了一个异常:

org.tmatesoft.svn.core.SVNException: svn: E175002: PUT of '/spielwiese/!svn/wrk/e9019037-4201-0010-b534-277444c0b279/postcommittesten.txt': 423 Locked (http://localhost:8081)
svn: E175002: PUT request failed on '/spielwiese/!svn/wrk/e9019037-4201-0010-b534-277444c0b279/postcommittesten.txt'
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:106)
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:90)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:739)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:369)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.performHttpRequest(DAVConnection.java:728)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.doPutDiff(DAVConnection.java:514)
at org.tmatesoft.svn.core.internal.io.dav.DAVCommitEditor.closeFile(DAVCommitEditor.java:335)
我错了什么?正确的方法是什么

我试着用这个。但是SVNCommitClient需要一个lokal工作副本来提交单个文件,我不想创建一个lokal工作副本。因此,我想直接将文件提交到给定位置的存储库中


如何提交被当前用户锁定的文件?

Subversion和DAV需要的不仅仅是作为拥有锁的用户才能对锁定的文件进行更改。您还必须拥有该文件的。当一个程序持有锁,而另一个程序修改由同一用户运行的文件时,可以防止出现问题。通常,锁令牌存储在一个工作副本上,在该副本上创建锁,代码将在那里检索它。但是,您似乎试图在没有工作副本的情况下将更改提交到文件

如果要提交到锁定的文件,则需要在获得
ISVNEditor
时提供锁定令牌,该编辑器不在您提供的代码中。在您提供的链接上的示例代码中,它是通过调用
SVNRepository
类上的
getCommitteEditor
方法完成的。有两种方法将
映射到您可以使用的锁令牌


为了拥有锁令牌,您必须在创建锁时存储它们。如果你没有锁令牌,你可以简单地偷锁。您可以通过将
force
参数设置为True(假设您有权窃取服务器上的锁)来调用。
SVNRepository上有一个and方法,但我不记得您是否可以用这种方法检索锁令牌,可能值得一试。

谢谢@Ben Reser。你击中了靶心。我使用了SVNRepository#getCommitteEditor(字符串,isvnWorkspaceMeditor)。但实际上,这是一种签名错误的方法

现在,我的代码可以读取,并且一切正常:

// Discover lock on the file
SVNLock lockedItem = this.repository.getLock(fileUrl);
Map<String, String> locks = new HashMap<String, String>();
if (lockedItem != null) {
    locks.put(lockedItem.getPath(), lockedItem.getID());
}

// Retrieve a commiteditor and provide the lock tokens
ISVNEditor editor = this.repository.getCommitEditor(
    comment, locks, true, new WorkspaceMediator());
SVNCommitInfo commitInfo = SVNUtils.modifyFile(editor,
    dirUrl, fileUrl, fileReader, size);
//发现文件上的锁
SVNLock lockedItem=this.repository.getLock(fileUrl);
Map locks=newhashmap();
如果(lockedItem!=null){
locks.put(lockedItem.getPath(),lockedItem.getID());
}
//检索CommitteEditor并提供锁令牌
ISVNEditor editor=this.repository.getcommitteeditor(
注释、锁定、true、新工作空间中介());
SVNCommitInfo commitInfo=SVNUtils.modifyFile(编辑器,
dirUrl、fileUrl、fileReader、size);

SVNKit是什么版本?SVN服务器的版本是什么?SVN工作副本格式的版本是什么?工作副本中的锁是通过SVNKit获得的吗?SVNKit 1.7.9。没有工作副本,因为我们直接提交到远程存储库。