Mercurial > hg > mercurial
changeset 669:c32869bd757b
Merge Gaya-8.0.x
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Sat, 12 Oct 2013 19:38:36 +0400 |
parents | bcee3a8b2c7b (current diff) 5abe150c9187 (diff) |
children | 718e4dbff3c3 |
files | mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java |
diffstat | 3 files changed, 40 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgFileUtil.java Fri Oct 04 15:59:42 2013 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgFileUtil.java Sat Oct 12 19:38:36 2013 +0400 @@ -30,6 +30,10 @@ */ public static File createTempDir() throws IOException { File parentDir = new File(FileUtil.getTempDirectory()); + return createTempDir(parentDir); + } + + public static File createTempDir(@NotNull File parentDir) throws IOException { parentDir.mkdirs(); int suffix = 0;
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java Fri Oct 04 15:59:42 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java Sat Oct 12 19:38:36 2013 +0400 @@ -1,6 +1,7 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; +import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.vcs.VcsException; import jetbrains.buildServer.vcs.VcsRoot; @@ -41,12 +42,30 @@ repPath = splitted[splitted.length-1]; } - File customWorkingDir = new File(canonicalCustomCloneDir, repPath); + File customWorkingDir = getCustomWorkingDir(canonicalCustomCloneDir, repPath); hgRoot.setCustomWorkingDir(customWorkingDir); return hgRoot; } + private File getCustomWorkingDir(@NotNull File parentCloneDir, @NotNull String repoPath) throws VcsException { + File customWorkingDir = new File(parentCloneDir, repoPath); + customWorkingDir.mkdirs(); + if (customWorkingDir.isDirectory()) + return customWorkingDir; + + customWorkingDir = new File(parentCloneDir, FileUtil.fixDirectoryName(repoPath)); + customWorkingDir.mkdirs(); + if (customWorkingDir.isDirectory()) + return customWorkingDir; + + try { + return HgFileUtil.createTempDir(parentCloneDir); + } catch (IOException e) { + throw new VcsException(e); + } + } + private File getCanonicalCustomCloneDir(@NotNull String customClonePath) throws VcsException { try { return new File(customClonePath).getCanonicalFile();
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java Fri Oct 04 15:59:42 2013 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java Sat Oct 12 19:38:36 2013 +0400 @@ -12,6 +12,7 @@ import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertNull; +import static org.testng.AssertJUnit.assertTrue; @Test public class HgVcsRootFactoryTest extends BaseMercurialTestCase { @@ -33,6 +34,21 @@ } + @TestFor(issues = "TW-32540") + public void custom_clone_dir_should_contain_only_valid_characters() throws Exception { + TempFiles tmp = new TempFiles(); + String urlWithoutPath = "http://acme:8000/"; + VcsRoot root = vcsRoot() + .withUrl(urlWithoutPath) + .withCloneRepositoryTo(tmp.createTempDir()) + .build(); + + HgVcsRoot hgRoot = new HgVcsRootFactory(serverPluginConfig().cachesDir(tmp.createTempDir()).build()).createHgRoot(root); + hgRoot.getCustomWorkingDir().mkdirs(); + assertTrue(hgRoot.getCustomWorkingDir().exists()); + } + + @TestFor(issues = "TW-28974") public void should_use_default_dirs() throws Exception { TempFiles tmp = new TempFiles();