Question

Say you have a specified SVN path like below, How can I know this item is a svn directory or a svn file. thanks.

http://cvs-server.test.com:8001/svn/test

Updated

            SVNURL svnUrl = SVNURL.parseURIEncoded(url);
            SVNRepository repos = SVNRepositoryFactory.create(svnUrl);
            ISVNAuthenticationManager authManager = 
            SVNWCUtil.createDefaultAuthenticationManager("user1","123");

            repos.setAuthenticationManager(authManager);

            SVNNodeKind nodeKind = repos.checkPath(url, repos.getLatestRevision());

Why did I get none even the url is a file ? I am sure this url exist in SVN. ORZ... There are many bugs with SVNkit .

Était-ce utile?

La solution 2

Try something like this:

String url = "http://cvs-server.test.com:8001/svn/test";
SVNURL svnUrl = SVNURL.parseURIEncoded(url);
SVNRepository repos = SVNRepositoryFactory.create(svnUrl);
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(DEFAULT_USER, DEFAULT_PASS);
repos.setAuthenticationManager(authManager); 
SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision());

nodeKind will be one of FILE, DIR or NONE.

Autres conseils

If you encounter into bugs, please report them to http://issues.tmatesoft.com/issues/SVNKIT .

checkPath doesn't work with URLs, it works with paths, absolute (i.e. relative to the repository root) or relative (to the URL for which SVNRepository instance was constructed) --- see its javadoc for more details

So you can just use this code

SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision());

or even

SVNNodeKind nodeKind = repos.checkPath("", -1);

the second variant will be faster because it doesn't perform getLatestRevision request, and it's a rather popular way to check the URL existence that is often used in SVNKit itself.

Alternatively you could use an absolute path (which should start with "/") but the path to be specified depends on your repository root. You can get the repository root by running

$ svn info "http://cvs-server.test.com:8001/svn/test"

or by running

repos.getRepositoryRoot(true);

from SVNKit code. The absolute path should start with "/" and be relative to the repository root obtained.

This is the correct way to do it:

public static boolean isFolder(String url) throws SVNException {
    SVNURL svnURL = SVNURL.parseURIEncoded(url);
    SVNRepository repos = SVNRepositoryFactory.create(svnURL);
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(DEFAULT_USER, DEFAULT_PASS);
    repos.setAuthenticationManager(authManager);
    SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision());
    System.out.println(nodeKind);
    return nodeKind != null && nodeKind == SVNNodeKind.DIR;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top