diff --git a/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/Ln.scala b/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/Ln.scala index 253cab16b78908eee3e236bc323e0ed437449690..cc8bf6afe2ea4f8f4fa4856ccf2047273ec4957a 100644 --- a/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/Ln.scala +++ b/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/Ln.scala @@ -1,7 +1,7 @@ package nl.lumc.sasc.biopet.extensions import java.io.File -import scala.sys.process.Process +import scala.sys.process.{ Process, ProcessLogger } import org.broadinstitute.gatk.queue.function.InProcessFunction import org.broadinstitute.gatk.utils.commandline.{ Input, Output } import nl.lumc.sasc.biopet.core.config.Configurable @@ -71,15 +71,21 @@ class Ln(val root: Configurable) extends InProcessFunction with Configurable { if (relative) { // workaround until we have `ln` that works with relative path (i.e. `ln -r`) - "ln -s '" + inRelative + "' '" + outCanonical + "'" + "ln -s " + inRelative + " " + outCanonical } else { - "ln -s '" + inCanonical + "' '" + outCanonical + "'" + "ln -s " + inCanonical + " " + outCanonical } } override def run { - val process = Process(cmd).run - logger.info("cmd: '" + cmd + "', exitcode: " + process.exitValue) + val stdout = new StringBuffer() + val stderr = new StringBuffer() + val process = Process(cmd).run(ProcessLogger(stdout append _ + "\n", stderr append _ + "\n")) + val exitcode = process.exitValue + if (exitcode != 0) { + throw new Exception("Error creating symbolic link, this was the original message: \n" + stderr) + } + logger.info("cmd: '" + cmd + "', exitcode: " + exitcode) } } diff --git a/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/extensions/LnUnitTest.scala b/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/extensions/LnUnitTest.scala index 76c609094230185cead8dd01789b4604beb87342..04f6758ca3141c4c9910c10daeef2cadaaccc11b 100644 --- a/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/extensions/LnUnitTest.scala +++ b/biopet-framework/src/test/scala/nl/lumc/sasc/biopet/extensions/LnUnitTest.scala @@ -19,7 +19,7 @@ class LnUnitTest extends TestNGSuite with Matchers { ln.relative = true ln.in = new File("/dir/nested/target.txt") ln.out = new File("/dir/nested/link.txt") - ln.cmd should ===("ln -s 'target.txt' '/dir/nested/link.txt'") + ln.cmd should ===("ln -s target.txt /dir/nested/link.txt") } @Test(description = "Target is one level above link, relative set to true") @@ -28,7 +28,7 @@ class LnUnitTest extends TestNGSuite with Matchers { ln.relative = true ln.in = new File("/dir/target.txt") ln.out = new File("/dir/nested/link.txt") - ln.cmd should ===("ln -s '../target.txt' '/dir/nested/link.txt'") + ln.cmd should ===("ln -s ../target.txt /dir/nested/link.txt") } @Test(description = "Target is two levels above link, relative set to true") @@ -37,7 +37,7 @@ class LnUnitTest extends TestNGSuite with Matchers { ln.relative = true ln.in = new File("/target.txt") ln.out = new File("/dir/nested/link.txt") - ln.cmd should ===("ln -s '../../target.txt' '/dir/nested/link.txt'") + ln.cmd should ===("ln -s ../../target.txt /dir/nested/link.txt") } @Test(description = "Target is a child of a directory one level above link, relative set to true") @@ -46,7 +46,7 @@ class LnUnitTest extends TestNGSuite with Matchers { ln.relative = true ln.in = new File("/dir/another_nested/target.txt") ln.out = new File("/dir/nested/link.txt") - ln.cmd should ===("ln -s '../another_nested/target.txt' '/dir/nested/link.txt'") + ln.cmd should ===("ln -s ../another_nested/target.txt /dir/nested/link.txt") } @Test(description = "Target is one level below link, relative set to true") @@ -55,7 +55,7 @@ class LnUnitTest extends TestNGSuite with Matchers { ln.relative = true ln.in = new File("/dir/nested/deeper/target.txt") ln.out = new File("/dir/nested/link.txt") - ln.cmd should ===("ln -s 'deeper/target.txt' '/dir/nested/link.txt'") + ln.cmd should ===("ln -s deeper/target.txt /dir/nested/link.txt") } @Test(description = "Target is two levels below link, relative set to true") @@ -64,7 +64,7 @@ class LnUnitTest extends TestNGSuite with Matchers { ln.relative = true ln.in = new File("/dir/nested/even/deeper/target.txt") ln.out = new File("/dir/nested/link.txt") - ln.cmd should ===("ln -s 'even/deeper/target.txt' '/dir/nested/link.txt'") + ln.cmd should ===("ln -s even/deeper/target.txt /dir/nested/link.txt") } @Test(description = "Relative set to false") @@ -73,7 +73,7 @@ class LnUnitTest extends TestNGSuite with Matchers { ln.relative = false ln.in = new File("/dir/nested/target.txt") ln.out = new File("/dir/nested/link.txt") - ln.cmd should ===("ln -s '/dir/nested/target.txt' '/dir/nested/link.txt'") + ln.cmd should ===("ln -s /dir/nested/target.txt /dir/nested/link.txt") } // TODO: test for case where abosolute is true and input paths are relative?