Hello,

> Hello,
> 
> I'm using SVNKIT 1.8 with SVN 1.8.5 and the SVN protocol to attempt to add
> files in bulk to my SVN repository.  I would like to have one method for
> adding and updating files and the below code successfully handles both when
> using the FILE protocol since the editor.addFile(file, null, -1) throws an
> SVNException. 

What exception are you speaking about? Could you provide the exception message 
and stack trace?

> When I switch to the SVN protocol (desired protocol), the
> editor.addFile(file, null, -1); doesn't throw an exception.  Instead the
> editor.closeEdit(); throws an exception which is not desired. 

Yes, SVNKit works this way with SVN protocol (checks are performed at 
closeEdit() stage). Note, that 
with HTTP protocols it works in a different way: permission checking and 
conflicts are checked at 
editor.addFile/openFile methods.

> Any ideas on
> how to use one API for both adding and updating files?

Yes, just check for file existence (SVNRepository#checkPath method) before 
calling 
getCommitEditor(). Note, that you can't do that after calling getCommitEditor() 
before calling 
closeEdit() or abortEdit(). See this article for details:

http://vcs.atspace.co.uk/2012/09/21/are-svnkit-methods-reenterable/

Also note, that if other users can alter the repository, they can add/remove 
that file between 
existence check, and the commit process will fail then (you may retry 
committing then or fail, 
depending if you want or don't want overwrite those changes silently). So a 
quick 
SVNRepository#checkPath call is the best you can do in this case.

--
Dmitry Pavlenko,
TMate Software,
http://subgit.com/ - git-svn bridge

> 
> 
> 
>     public void addFiles(Map<String, String> data) throws Exception {
>         TreeSet<String> filesToCreate = new TreeSet<String>(data.keySet());
> 
>         SVNRepository repo = null;
>         ISVNEditor editor = null;
>         try {
>           repo = openSession();
>           editor = repo.getCommitEditor("Adding files.", null);
>           editor.openRoot(-1);
>           for (String file : filesToCreate) {
>             try {
>               editor.addFile(file, null, -1);
>             } catch (SVNException e) {
>               editor.openFile(file, -1);
>             }
>             editor.applyTextDelta(file, null);
>             SVNDeltaGenerator gen = new SVNDeltaGenerator();
>             String checksum = gen.sendDelta(file, new
> ByteArrayInputStream(data.get(file).getBytes()), editor, true);
>             editor.closeFile(file, checksum);
>           }
>           editor.closeEdit();
>         } catch (Exception ex) {
>           abort(editor);
>           throw new Exception(ex.toString(), ex);
>         } finally {
>           closeSession(repo);
>         }
>       }
> 
> 
> 
> --
> View this message in context:
> http://subversion.1072662.n5.nabble.com/One-API-to-handle-adding-and-updat
> ing-files-tp186109.html Sent from the SVNKit - Users mailing list archive
> at Nabble.com.


Reply via email to