# HG changeset patch # User Dmitry Neverov # Date 1381591709 -14400 # Node ID 5abe150c918734f3a943dd72d23d7c6e76647cdf # Parent 55cf557a14de887c51fc693fe4e14f23cced1cca TW-32540 ensure a custom clone dir has only valid symbols diff -r 55cf557a14de -r 5abe150c9187 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgFileUtil.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgFileUtil.java Tue Oct 01 12:51:13 2013 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgFileUtil.java Sat Oct 12 19:28:29 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; diff -r 55cf557a14de -r 5abe150c9187 mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java Tue Oct 01 12:51:13 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java Sat Oct 12 19:28:29 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; @@ -40,12 +41,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(); diff -r 55cf557a14de -r 5abe150c9187 mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java Tue Oct 01 12:51:13 2013 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java Sat Oct 12 19:28:29 2013 +0400 @@ -14,6 +14,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 { @@ -47,6 +48,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();