首页 > 解决方案 > 为什么 Java SVNKit 在错误的位置添加文件夹

问题描述

在我的 svn 存储库中,目录层次结构是这样的:

/dirA(exists)/
   /dirB(exists)/

哪个 dirB 在 dirA 中,并且两者都存在。

现在,我想在 dirB 中添加一个文件夹(dirC),在 dirC 中添加一个文件(file1.txt),所以我希望目录层次结构是这样的:

/dirA(exists)/
        /dirB(exists)/
                /dirC(added)/
                        /file1.txt(added)

使用 SVNKit,我的 SVNRepository 的实例指向 dirA,我使用 getCommitEditor() 获取 ISVNEditor 的实例,并调用它的 openRoot(-1) 方法,如下所示:

ISVNEditor svnEditor = svnRepository.getCommitEditor("add folder and file.", null);
svnEditor.openRoot(-1);

我调用 ISVNEditor 的 addDir() 方法和 addFile() 方法来添加文件夹和文件,如下所示:

svnEditor.addDir("dirB/dirC", null, -1);
svnEditor.addFile("dirB/dirC/file1.txt", null, -1);
svnEditor.applyTextDelta("dirB/dirC/file1.txt", null);

SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
String checksum = deltaGenerator.sendDelta("dirB/dirC/file1.txt", new ByteArrayInputStream(data), svnEditor, true);
svnEditor.closeFile("dirB/dirC/file1.txt", checksum);//Closes the new added file.
svnEditor.closeDir(); //Closes the new added folder.
svnEditor.closeDir(); //Closes the root folder.

svnEditor.closeEdit();

之后,为什么将 dirC 添加到 dirA 中,而不是 dirB 中,目录层次结构变成了这样:

/dirA(root)/
        /dirB(exists)/
        /dirC(added)/
                /file1.txt(added)

当我打电话时,我已经表明 dirC 在 dirB 下

svnEditor.addDir("dirB/dirC", null, -1),

但它似乎不起作用?提前感谢您回答我的问题。

标签: javasvnsvnkit

解决方案


为了更改文件夹,您需要提供 dirB 的本地版本。

//provide your local revision of dirB
long r = ...;
svnEditor.openDir( "dirB" , r );

所以现在你在你的目录下。到达那里后,您可以在 dirB 下添加文件或文件夹。如果你想更深入地说,例如在 dirC 中,那么你必须再次提供你的 dirC 的本地版本并在那里添加一个文件。


推荐阅读