From ca047b7953347aff6db95dc1668088d2ac08e874 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Fri, 30 Sep 2022 11:01:27 +0200 Subject: [PATCH] Catch SvnCatCommand exception for trying to read content from nodes which are not files. --- gradle/changelog/svncatcommand.yaml | 2 + .../scm/repository/spi/SvnCatCommand.java | 37 ++++++------------- .../scm/repository/spi/SvnCatCommandTest.java | 11 ++++++ 3 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 gradle/changelog/svncatcommand.yaml diff --git a/gradle/changelog/svncatcommand.yaml b/gradle/changelog/svncatcommand.yaml new file mode 100644 index 0000000000..e8e74a367b --- /dev/null +++ b/gradle/changelog/svncatcommand.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Catch SVN error for cat command on non-file nodes ([#2127](https://github.com/scm-manager/scm-manager/pull/2127)) diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnCatCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnCatCommand.java index 010fb7f73e..280bf18551 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnCatCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnCatCommand.java @@ -48,11 +48,9 @@ import static sonia.scm.NotFoundException.notFound; //~--- JDK imports ------------------------------------------------------------ /** - * * @author Sebastian Sdorra */ -public class SvnCatCommand extends AbstractSvnCommand implements CatCommand -{ +public class SvnCatCommand extends AbstractSvnCommand implements CatCommand { /** * the logger for SvnCatCommand @@ -62,8 +60,7 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand //~--- constructors --------------------------------------------------------- - SvnCatCommand(SvnContext context) - { + SvnCatCommand(SvnContext context) { super(context); } @@ -71,21 +68,17 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand @Override public void getCatResult(CatCommandRequest request, OutputStream output) { - if (logger.isDebugEnabled()) - { + if (logger.isDebugEnabled()) { logger.debug("try to get content for {}", request); } String revision = request.getRevision(); - if (SvnUtil.isTransactionEntryId(revision)) - { + if (SvnUtil.isTransactionEntryId(revision)) { String txn = SvnUtil.getTransactionId(revision); getCatFromTransaction(request, output, txn); - } - else - { + } else { long revisionNumber = SvnUtil.getRevisionNumber(revision, repository); @@ -107,15 +100,12 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand logger.debug("try to read content from revision {} and path {}", revision, request.getPath()); - try - { + try { SVNRepository svnRepository = open(); svnRepository.getFile(request.getPath(), revision, new SVNProperties(), output); - } - catch (SVNException ex) - { + } catch (SVNException ex) { handleSvnException(request, ex); } } @@ -126,6 +116,8 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand throw notFound(entity("Path", request.getPath()).in("Revision", request.getRevision()).in(repository)); } else if (SVNErrorCode.FS_NO_SUCH_REVISION.getCode() == svnErrorCode) { throw notFound(entity("Revision", request.getRevision()).in(repository)); + } else if (SVNErrorCode.FS_NOT_FILE.getCode() == svnErrorCode) { + logger.debug("Skip cat command for non-file node"); } else { throw new InternalRepositoryException(repository, "could not get content from revision", ex); } @@ -137,20 +129,15 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand SVNClientManager cm = null; - try - { + try { cm = SVNClientManager.newInstance(); SVNLookClient client = cm.getLookClient(); client.doCat(context.getDirectory(), request.getPath(), txn, output); - } - catch (SVNException ex) - { + } catch (SVNException ex) { throw new InternalRepositoryException(repository, "could not get content from transaction", ex); - } - finally - { + } finally { SvnUtil.dispose(cm); } } diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnCatCommandTest.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnCatCommandTest.java index 26616f53df..b16b691db0 100644 --- a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnCatCommandTest.java +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnCatCommandTest.java @@ -135,4 +135,15 @@ public class SvnCatCommandTest extends AbstractSvnCommandTestBase { return content; } + + @Test + public void shouldNotThrowExceptionForNonFileNodeCatCommand() throws IOException { + CatCommandRequest request = new CatCommandRequest(); + request.setPath("/"); + request.setRevision("1"); + + InputStream catResultStream = new SvnCatCommand(createContext()).getCatResultStream(request); + + catResultStream.close(); + } }